|
85867
|
2946
|
5
|
2026-05-28T13:24:30.510334+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974670510_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
-3693216725545869923
|
4739222772041917682
|
click
|
hybrid
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
iTerm2ShellEditViewSessionScriptsProfilesWindowHelplah]-zshDOCKER881DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%85ec2-user@ip-10-30-129-...100% <478• Thu 28 May 16:24:30181ec2-user@ip-10-30-140-…₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
85865
|
NULL
|
NULL
|
NULL
|
|
85866
|
2947
|
4
|
2026-05-28T13:24:26.562512+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974666562_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
4706174618500851082
|
-2241707253006846750
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85865
|
2946
|
4
|
2026-05-28T13:24:18.688277+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974658688_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
4761603861393910889
|
-3250018833119170428
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85864
|
2947
|
3
|
2026-05-28T13:23:56.047619+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974636047_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt
Gemini said
Gemini said
I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:
UpdateProcessManagerTest.php
.
Because the actual source files (such as
UpdateProcessManager.php
or
ReindexTargetStatsReporter.php
) are not included in the snippet, I cannot analyze them for potential issues.
If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.
Good response
Bad response
Share & export
Copy
Show more options...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"not","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"forward it during that setter call (and instead calls it during","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"doUpdateEntitiesChunk","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), the test might be passing for the wrong reason or could break if the internal implementation changes.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"2. Inconsistent Environment Configuration in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the new test, you instantiate the processor manually using","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"new UpdateProcessManager(...)","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"instead of using the updated","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper method.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"By bypassing","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you lose the centralized setup. If the constructor requirements for","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"change in the future, this test will break and require manual updating, whereas tests using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"will be insulated from that change.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Refactor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to utilize a slightly modified or parameterized version of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to keep the test suite DRY (Don't Repeat Yourself).","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"3. Tight Coupling to Log Strategies (withAnyArgs)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3. Tight Coupling to Log Strategies (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the precise log assertions from","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"were replaced with:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Log::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'info'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();\nLog::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'debug'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"\"[ EsUpdateProcessManager ] Finished updating entities in ES\"","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), these tests will still pass.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Instead of completely silencing the logger with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", use","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"with()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that specific key tracking or lifecycle messages are still generated.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"4. Risks with","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Default Value (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes = 0","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The helper method signature was changed to","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"private function prepareStatusManager(int $invokeTimes = 0): void","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"When","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"is","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", it sets an explicit expectation that","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"should","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"never","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"be called:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"else","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"{","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$batchStatusManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->never())->method(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":");\n}","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If any future test calls","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"without arguments (defaulting to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), but the system under test","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"does","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"execute an initialization step that invokes","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"strictly means the manager shouldn't interact with the target at all.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said ignore tests for now. Just focus on non test files","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ignore tests for now. Just focus on non test files","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Because the actual source files (such as","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"or","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ReindexTargetStatsReporter.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") are not included in the snippet, I cannot analyze them for potential issues.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
8922624913301653512
|
-3141921446945869692
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt
Gemini said
Gemini said
I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:
UpdateProcessManagerTest.php
.
Because the actual source files (such as
UpdateProcessManager.php
or
ReindexTargetStatsReporter.php
) are not included in the snippet, I cannot analyze them for potential issues.
If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.
Good response
Bad response
Share & export
Copy
Show more options...
|
85862
|
NULL
|
NULL
|
NULL
|
|
85863
|
2946
|
3
|
2026-05-28T13:23:48.204427+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974628204_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"}]...
|
-4046362202999749048
|
-8005837631808589692
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring...
|
85861
|
NULL
|
NULL
|
NULL
|
|
85862
|
2947
|
2
|
2026-05-28T13:23:25.539134+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974605539_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
1451045180245282315
|
-4547070918964793212
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85861
|
2946
|
2
|
2026-05-28T13:23:17.726573+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974597726_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"not","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"forward it during that setter call (and instead calls it during","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"doUpdateEntitiesChunk","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), the test might be passing for the wrong reason or could break if the internal implementation changes.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"2. Inconsistent Environment Configuration in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the new test, you instantiate the processor manually using","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"new UpdateProcessManager(...)","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"instead of using the updated","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-3076146662636488346
|
-3393588663428550524
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85860
|
2947
|
1
|
2026-05-28T13:22:55.167198+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974575167_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"not","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"forward it during that setter call (and instead calls it during","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"doUpdateEntitiesChunk","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), the test might be passing for the wrong reason or could break if the internal implementation changes.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"2. Inconsistent Environment Configuration in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the new test, you instantiate the processor manually using","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"new UpdateProcessManager(...)","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"instead of using the updated","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper method.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"By bypassing","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you lose the centralized setup. If the constructor requirements for","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"change in the future, this test will break and require manual updating, whereas tests using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"will be insulated from that change.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Refactor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to utilize a slightly modified or parameterized version of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to keep the test suite DRY (Don't Repeat Yourself).","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"3. Tight Coupling to Log Strategies (withAnyArgs)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3. Tight Coupling to Log Strategies (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the precise log assertions from","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"were replaced with:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Log::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'info'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();\nLog::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'debug'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"\"[ EsUpdateProcessManager ] Finished updating entities in ES\"","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), these tests will still pass.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Instead of completely silencing the logger with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", use","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"with()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that specific key tracking or lifecycle messages are still generated.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"4. Risks with","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Default Value (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes = 0","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The helper method signature was changed to","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"private function prepareStatusManager(int $invokeTimes = 0): void","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"When","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"is","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", it sets an explicit expectation that","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"should","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"never","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"be called:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"else","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"{","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$batchStatusManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->never())->method(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":");\n}","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If any future test calls","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"without arguments (defaulting to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), but the system under test","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"does","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"execute an initialization step that invokes","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"strictly means the manager shouldn't interact with the target at all.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said ignore tests for now. Just focus on non test files","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ignore tests for now. Just focus on non test files","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
8638953882308888358
|
-3141921446946918268
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt...
|
85858
|
NULL
|
NULL
|
NULL
|
|
85859
|
2946
|
1
|
2026-05-28T13:22:47.360512+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974567360_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"not","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"forward it during that setter call (and instead calls it during","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"doUpdateEntitiesChunk","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), the test might be passing for the wrong reason or could break if the internal implementation changes.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"2. Inconsistent Environment Configuration in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the new test, you instantiate the processor manually using","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"new UpdateProcessManager(...)","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"instead of using the updated","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper method.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"By bypassing","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you lose the centralized setup. If the constructor requirements for","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"change in the future, this test will break and require manual updating, whereas tests using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"will be insulated from that change.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Refactor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to utilize a slightly modified or parameterized version of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to keep the test suite DRY (Don't Repeat Yourself).","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"3. Tight Coupling to Log Strategies (withAnyArgs)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3. Tight Coupling to Log Strategies (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the precise log assertions from","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"were replaced with:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Log::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'info'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();\nLog::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'debug'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"\"[ EsUpdateProcessManager ] Finished updating entities in ES\"","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), these tests will still pass.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Instead of completely silencing the logger with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", use","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"with()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that specific key tracking or lifecycle messages are still generated.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"4. Risks with","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Default Value (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes = 0","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The helper method signature was changed to","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"private function prepareStatusManager(int $invokeTimes = 0): void","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"When","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"is","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", it sets an explicit expectation that","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"should","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"never","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"be called:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"else","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"{","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$batchStatusManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->never())->method(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":");\n}","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-4772193127620586207
|
-3430147425052118908
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}...
|
85857
|
NULL
|
NULL
|
NULL
|
|
85858
|
2947
|
0
|
2026-05-28T13:22:24.616575+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974544616_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-7498500315417812516
|
-3393571070167994236
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85857
|
2946
|
0
|
2026-05-28T13:22:16.823816+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974536823_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-3373102755705057410
|
-3394138419241537404
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85856
|
NULL
|
0
|
2026-05-28T13:21:53.904718+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974513904_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy....
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
9181569831850562553
|
-3250018833119170396
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy....
|
85854
|
NULL
|
NULL
|
NULL
|
|
85855
|
NULL
|
0
|
2026-05-28T13:21:46.351494+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974506351_m1.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
-333758984105209474
|
-2240598945286052638
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close...
|
85852
|
NULL
|
NULL
|
NULL
|
|
85854
|
2945
|
21
|
2026-05-28T13:21:23.355313+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974483355_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-5626217824370242690
|
-3393571070169042812
|
visual_change
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85853
|
2945
|
20
|
2026-05-28T13:21:20.130898+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974480130_m2.jpg...
|
Firefox
|
jiminny/app: Jiminny Web Application — Work
|
1
|
github.com/jiminny/app
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"jiminny/app: Jiminny Web Application","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"jiminny/app: Jiminny Web Application","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.064494684,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
-333758984105209474
|
-2240598945286052638
|
visual_change
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
jiminny/app: Jiminny Web Application
jiminny/app: Jiminny Web Application
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close...
|
85851
|
NULL
|
NULL
|
NULL
|
|
85852
|
2944
|
15
|
2026-05-28T13:21:15.803248+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974475803_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
6262037593010571414
|
-9167764136647970684
|
click
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85851
|
2945
|
19
|
2026-05-28T13:21:15.661530+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974475661_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.14245346,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
5512798709196531258
|
-2241847994790152988
|
click
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85850
|
2944
|
14
|
2026-05-28T13:21:12.455073+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974472455_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-7524355726528610679
|
-9167764153826791292
|
visual_change
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()...
|
85849
|
NULL
|
NULL
|
NULL
|
|
85848
|
2945
|
18
|
2026-05-28T13:21:10.607206+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974470607_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.14245346,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
3935047927001615761
|
-4474368010461776649
|
visual_change
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket...
|
85847
|
NULL
|
NULL
|
NULL
|
|
85849
|
2944
|
13
|
2026-05-28T13:21:09.404449+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974469404_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹ >0 lol-zshDOCKER881DEV (docker)₴82-zshN3screenpipe"O &4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phpukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddockerexec -it docker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] $ ;xddockerexeс-itdocker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv•lluen/lneallnbalahnleandc:1a ^nW85ec2-user@ip-10-30-129-...100% C8• Thu 28 May 16:21:08181ec2-user@ip-10-30-140-…₴7PS$I31Ph.SlackPHPruntime:8.5.5Loadedconfig default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697I 100%Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use(they willstop working in next major release):Rule set"@PHP74Migration"is deprecated. Use"@PHP7x4Migration" instead.Rule set "@PHP80Migration"Ruleset"@PHP81Migration"is deprecated.Use "@PHP8x0Migration" instead.is deprecated.UseRule set"@PHP82Migration""@PHP8x1Migration" instead.is deprecated. Use"@PHP8x?Migration" instead.Ruleset"@PHP83Migration"is deprecated. Use"@PHP8x3Migration" instead.Ruleset"@PHP84Migration"is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $0...
|
NULL
|
2641753252151865839
|
NULL
|
visual_change
|
ocr
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹ >0 lol-zshDOCKER881DEV (docker)₴82-zshN3screenpipe"O &4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phpukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddockerexec -it docker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] $ ;xddockerexeс-itdocker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv•lluen/lneallnbalahnleandc:1a ^nW85ec2-user@ip-10-30-129-...100% C8• Thu 28 May 16:21:08181ec2-user@ip-10-30-140-…₴7PS$I31Ph.SlackPHPruntime:8.5.5Loadedconfig default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697I 100%Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use(they willstop working in next major release):Rule set"@PHP74Migration"is deprecated. Use"@PHP7x4Migration" instead.Rule set "@PHP80Migration"Ruleset"@PHP81Migration"is deprecated.Use "@PHP8x0Migration" instead.is deprecated.UseRule set"@PHP82Migration""@PHP8x1Migration" instead.is deprecated. Use"@PHP8x?Migration" instead.Ruleset"@PHP83Migration"is deprecated. Use"@PHP8x3Migration" instead.Ruleset"@PHP84Migration"is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $0...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85847
|
2945
|
17
|
2026-05-28T13:21:07.427327+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974467427_m2.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(...
|
[{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11569149,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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.85638297,"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":"ServiceTest","depth":6,"bounds":{"left":0.87167555,"top":0.019952115,"width":0.043882977,"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 'ServiceTest'","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 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.010305851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.009640957,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"bounds":{"left":0.41589096,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"bounds":{"left":0.4245346,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"bounds":{"left":0.43550533,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"bounds":{"left":0.44414893,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"bounds":{"left":0.45279256,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"bounds":{"left":0.4637633,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"bounds":{"left":0.47473404,"top":0.09896249,"width":0.024268618,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"bounds":{"left":0.5013298,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"bounds":{"left":0.51230055,"top":0.09896249,"width":0.029587766,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"bounds":{"left":0.7237367,"top":0.09896249,"width":0.02825798,"height":0.01915403},"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":"45","depth":4,"bounds":{"left":0.6938165,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.70611703,"top":0.123703115,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"bounds":{"left":0.71542555,"top":0.123703115,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","depth":4,"bounds":{"left":0.72706115,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.12210695,"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.7463431,"top":0.12210695,"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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
4911831517688950861
|
-6520523836328617179
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#12121 on JY-20963-fix-im Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85846
|
2945
|
16
|
2026-05-28T13:20:46.063045+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974446063_m2.jpg...
|
Slack
|
backend (Channel) - Jiminny Inc - 2 new items - Sl backend (Channel) - Jiminny Inc - 2 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
ai-chapter
alerts...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.024268618,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54089093,"top":0.18994413,"width":0.020279255,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.044215426,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":25,"bounds":{"left":0.54521275,"top":0.28411812,"width":0.058843084,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.04454787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":18,"bounds":{"left":0.54521275,"top":0.3064645,"width":0.04155585,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.022273935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54488033,"top":0.35913807,"width":0.019614361,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.012300532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54488033,"top":0.38148445,"width":0.00930851,"height":0.014365523}}],"role_description":"text"}]...
|
-2980788361395771722
|
-5774506732591563009
|
visual_change
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
ai-chapter
alerts
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obiectXMlinbox (1294) - Mias kowlikSlimlZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavina amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page<> Codejiminny / app &17 Pull requests 336. Agents© ActionsQ WikiJY-2096I1 OpenLaKVLQ) ConversationLakyLakJIKATChange•FIxt_Lak'nikolay-aclauaActivityMoreJiminnY ….uinrea@ Threads6 HuddlesDrafts & sent© Directories01Ah External connections# Starredolatform-backend…8 platform-inner-team@) Channels# ai-chapter# alerts# backend# bugs# confusion-dlinid# donut_time# enpineerine# general# happy_birthdayA infosec intemal all# infra-changest infrastructure del# ibu-team-info# jiminny-bg# olatform-team# platform-tickets# product launches# random# releases# support# thank-yous# the peoole of fimill^ Direct messagesllivana Netceval8. Vasil Vasilev Ef8. Stefka Stoyanova O8?. Stoyan Tomov® Petko KashinskiTO0У L7Thu 28 May 16:20:46Q Describe what you are looking forw.mhlcKend32llechun.crew.warkhearois. wouthnktremooranieto covear0n ofseslestneo8 1720$© Files& BookmarkeeDDor MeTiesKeearnins& PinsFriday, April 17th -llian Kyuchukov 10:17 AMI won't be able to join the Backend Meeting, as there is a prod issueThursday. Apnil 3othSaved for later • Due 21 days agoNikolay Ivanoy 10:58 AMFor those using make cs-fix and getting annoved by how long it takes (since it scans the entire project), you can now use make cs-fix-branch. It will fix only the fles thatdiffer from master, and it runs in just a couple of secondsHH3 P10Ilian Kyuchukov 9:32 AMwtnsothuh.com/iminnv/ann/oulll7050Since we started using/evaluating Claude Code, adding the dev rules for it.Reformated .windsurfrules to MD format and made a symlink to CLAUDE.md (so we can use one file for both, until we need to separate them)#450 nhKe.dnudescrec 2alJIRA: JY-XXXXChanges:• Reformat .windsurfrules to MD format, copied the rules to CLAUDE.md as welljiminry/app May 7th| Added by GitHubFriday, May 15th~llian Kyuchukov 910AMFor today's chapter we will take a look at tech days ideas and Claude Code usage/tips2reolice Last moly 13 davs andToday~Vasil Vasilev # 3:44 PM@here guys, please do not deploy until further notice, I am scheduling logs of activities for reindexing, for the MCP, and a deploy will break the processVasil Vasilev # 3:52 PMAll activities are scheduled, releases are okay nowMessage #backendAa...
|
85845
|
NULL
|
NULL
|
NULL
|
|
85845
|
2945
|
15
|
2026-05-28T13:20:43.065422+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974443065_m2.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 2 new items - S Vasil Vasilev (DM) - Jiminny Inc - 2 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.015292553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.024268618,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54089093,"top":0.18994413,"width":0.020279255,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.044215426,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":25,"bounds":{"left":0.54521275,"top":0.28411812,"width":0.058843084,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.04454787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":18,"bounds":{"left":0.54521275,"top":0.3064645,"width":0.04155585,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":16,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54521275,"top":0.35913807,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.022273935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54488033,"top":0.38148445,"width":0.019614361,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.012300532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54488033,"top":0.4038308,"width":0.00930851,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.010638298,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":3,"bounds":{"left":0.54521275,"top":0.42617717,"width":0.00731383,"height":0.014365523}}],"role_description":"text"}]...
|
-7407170306385627196
|
-8116484152070029697
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obtectXMlinbox (1224) - Mias kowstikSlimZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~<> Codejiminny / app &17 Pull requests 336. AgentsThat is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavina amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page© ActionsQ WikiJY-2096LaKVLQ) ConversationLakyLakJIKATChange•FIxt_Lak'nikolay.aclauaActivityMoreJiminnYinrede@ Threads6 HuddlesDrafts & sent© Directories01Ah External connections# Starredolatform-backend…8 platform-inner-team@) Channels# backend# ai-chapten# alerts# bugs# confusion-dlinid# donut_time# enpineerine# general# happy_birthdayA infosec interal all# infra-changest infrastructure del#ibu-team-info# jiminny-bg# olatform-team# platform-tickets# product launches"andom# releases# support# thank-yous# the peoole of fimill^ Direct messagesllivana Netceve. Vasil Vasilev Ef8. Stefka Stoyanova O88. Stoyan Tomov® Petko Kashinski8• Thu 28 May 16:20:43Q Describe what you are looking for€. Vasil Vasilev Me MessagerNeRdd canv© Files& PinsVasil Vasilev I 3:11 PMpredis поддьржа set(Skey, Svalue. ['nx' = true, ex =60)c phpredis не ставаLukas Kovalik 3:11 PMтака май не работеше Sresult = Redis-set(StestKey, StestValue 'EX" Swl. "NX"): а така ла Sresult = Redisuset(StestKey, StestValue l'nx' 'ex' => Stll):wsilasileukhaemЗO0OТО ПDOОВХИ НеСКHLukas Kovallk 3.7PMили обоитноVasil Vasilev IE 3:12 PMобратното може да eLukas Kovalik 3:12PMможе и да бръкамVasil Vasilev # 3:12 PMв кода нмаSlockAcquired - Redis: :set(self:: POLLING_LOCK_KEY, json_encode(SlockData), 'EX*, self:: LOCK_TTL_SECONOS, *NX*):значи пьрвото работиuukas Kovalnk Kakoда и в арр/Services/Crm/Hubspot/Client.php:103Vasil Vasiley 3:14 pMwuKasKovalkkho?werwwensm.wewbBereMulMnosEhcwcooucnoneahhieethhormertokVasil Vasilev B 3:17 PMLukas Kovalik 3:17PMдано няма нещо промененоVasil Vasilev # 3:17 PMще си го оставя както eLukas Kovalik 3:18 PMок, мисля че е само ideWlwvacllew 22ko1МІЛИІНА АЗТОМАИНЙ ОЛАЛИННЯТ НА A ЛОЯМресетването на ЕС лескоиптора обаче е много алекратен коментар.Message Vasil Vasilev In a meeting • Google Calendar...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85844
|
2944
|
12
|
2026-05-28T13:20:42.958181+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974442958_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 2 new items - S Vasil Vasilev (DM) - Jiminny Inc - 2 new items - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":16,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"on_screen":true,"role_description":"text"}]...
|
7038715935395544315
|
-8116484152070029697
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
iTerm2ShellEditViewSessionScriptsProfilesWindowHelp(ah]-zshDOCKER-₴81DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%85ec2-user@ip-10-30-129-...100% <478• Thu 28 May 16:20:42181ec2-user@ip-10-30-140-…₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
85842
|
NULL
|
NULL
|
NULL
|
|
85843
|
2945
|
14
|
2026-05-28T13:20:39.081643+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974439081_m2.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 2 new items - S Vasil Vasilev (DM) - Jiminny Inc - 2 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Today at 2:45:14 PM
2:45
1.
Shared Elasticsearch Sockets:
Because
pcntl_fork()
clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in
resetAfterFork()
(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and
cURL
exceptions.
2.
Supervisor Shutdown Deadlock:
In
reapChildren()
, calling
pcntl_waitpid()
without the
WNOHANG
flag makes it a blocking call. If one child process gets stuck (e.g., waiting on a network timeout), the parent supervisor will freeze indefinitely and completely ignore your 10-second graceful shutdown logic.
(edited)
Today at 2:45:29 PM
2:45
3.
Non-Atomic Redis Locks:
The new
ReindexTargetStatsReporter
checks the lock with
get
and then creates it with
set
. Because the workers are truly parallel, they can both read
null
at the exact same microsecond and both push duplicate metrics to Datadog. This needs to be a single, atomic command (e.g.,
set
with
NX
).
Vasil Vasilev
Today at 2:56:52 PM
2:56 PM
1 e добър коментар,
Today at 2:56:55 PM
2:56
2 е intentional,
Today at 2:57:50 PM
2:57
3 също е intentional поради факта, че phpredis driver-a не поддържа set ex +nx параметри, и трябва да се пуснат две операции set + expire
Lukas Kovalik
Today at 3:07:16 PM
3:07 PM
ок, аз го пуснах пак през gemini
Today at 3:07:31 PM
3:07
за третата точка обаче наистина ли няма подържка...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.015292553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.024268618,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54089093,"top":0.18994413,"width":0.020279255,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.044215426,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":25,"bounds":{"left":0.54521275,"top":0.28411812,"width":0.058843084,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.04454787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":18,"bounds":{"left":0.54521275,"top":0.3064645,"width":0.04155585,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":15,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54521275,"top":0.35913807,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.022273935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54488033,"top":0.38148445,"width":0.019614361,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.012300532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54488033,"top":0.4038308,"width":0.00930851,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.010638298,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":3,"bounds":{"left":0.54521275,"top":0.42617717,"width":0.00731383,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54454786,"top":0.44852355,"width":0.032247342,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.025265958,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54521275,"top":0.4708699,"width":0.022273935,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":15,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.025930852,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54488033,"top":0.49321628,"width":0.022938829,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"general","depth":15,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.016289894,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54488033,"top":0.51556265,"width":0.013297873,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"happy_birthday","depth":15,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.033909574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":13,"bounds":{"left":0.54521275,"top":0.53790903,"width":0.030917553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infosec_internal_all","depth":15,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.041888297,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":19,"bounds":{"left":0.54355055,"top":0.5602554,"width":0.040226065,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":15,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.029587766,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.5826017,"width":0.02825798,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infrastructure_dev","depth":15,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.040226065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":17,"bounds":{"left":0.54355055,"top":0.6049481,"width":0.038896278,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jbu-team-info","depth":15,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.029920213,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.6272945,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":15,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.023271276,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54355055,"top":0.64964086,"width":0.021609042,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-team","depth":15,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.03158245,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54521275,"top":0.67198724,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":15,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.034906916,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.6943336,"width":0.031914894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":15,"bounds":{"left":0.5422208,"top":0.71668,"width":0.03856383,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.71668,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.71668,"width":0.03557181,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"random","depth":15,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.016954787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54421544,"top":0.7390263,"width":0.014960106,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":15,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.0016622341,"height":0.014365523}},{"char_start":1,"char_count":7,"bounds":{"left":0.54388297,"top":0.7613727,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"support","depth":15,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.017287234,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54454786,"top":0.78371906,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":15,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.024601065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54421544,"top":0.80606544,"width":0.022606382,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":15,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.045212764,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":20,"bounds":{"left":0.54421544,"top":0.8284118,"width":0.04720745,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Iliyana Netseva","depth":15,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.03324468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":14,"bounds":{"left":0.54355055,"top":0.8810854,"width":0.031914894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":16,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.026595745,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54521275,"top":0.9034318,"width":0.023271276,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Stefka Stoyanova","depth":15,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.037898935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54488033,"top":0.92577815,"width":0.03523936,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Stoyan Tomov","depth":15,"bounds":{"left":0.5422208,"top":0.9481245,"width":0.030917553,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.9481245,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":11,"bounds":{"left":0.54488033,"top":0.9481245,"width":0.027925532,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Petko Kashinski","depth":15,"bounds":{"left":0.5422208,"top":0.97047085,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.97047085,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":14,"bounds":{"left":0.54521275,"top":0.97047085,"width":0.03158245,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":15,"bounds":{"left":0.5422208,"top":0.9928172,"width":0.03523936,"height":0.0031923384},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Todor Stamatov","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.034574468,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.038231384,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Ves","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.007978723,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Mira","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.010305851,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.032912236,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"James Graham","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.031914894,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.029587766,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"you","depth":15,"bounds":{"left":0.5744681,"top":0.9952115,"width":0.0063164895,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.021941489,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.011635638,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":9,"bounds":{"left":0.60206115,"top":0.09177973,"width":0.030917553,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":11,"bounds":{"left":0.61136967,"top":0.10055866,"width":0.018949468,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.61136967,"top":0.10055866,"width":0.0039893617,"height":0.012769354}},{"char_start":1,"char_count":7,"bounds":{"left":0.61535907,"top":0.10055866,"width":0.014960106,"height":0.012769354}}],"role_description":"text"},{"role":"AXRadioButton","text":"Add canvas","depth":10,"bounds":{"left":0.63397604,"top":0.09177973,"width":0.034242023,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Add canvas","depth":12,"bounds":{"left":0.64328456,"top":0.10055866,"width":0.022273935,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.64328456,"top":0.10055866,"width":0.0033244682,"height":0.012769354}},{"char_start":1,"char_count":9,"bounds":{"left":0.6462766,"top":0.10055866,"width":0.019281914,"height":0.012769354}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":9,"bounds":{"left":0.66921544,"top":0.09177973,"width":0.020944148,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":11,"bounds":{"left":0.67852396,"top":0.10055866,"width":0.008976064,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.67852396,"top":0.10055866,"width":0.0026595744,"height":0.012769354}},{"char_start":1,"char_count":4,"bounds":{"left":0.6811835,"top":0.10055866,"width":0.0063164895,"height":0.012769354}}],"role_description":"text"},{"role":"AXRadioButton","text":"Pins","depth":9,"bounds":{"left":0.69148934,"top":0.09177973,"width":0.020279255,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Pins","depth":11,"bounds":{"left":0.70079786,"top":0.10055866,"width":0.00831117,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.70079786,"top":0.10055866,"width":0.0026595744,"height":0.012769354}},{"char_start":1,"char_count":3,"bounds":{"left":0.7034575,"top":0.10055866,"width":0.0056515955,"height":0.012769354}}],"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":9,"bounds":{"left":0.71276593,"top":0.09177973,"width":0.010970744,"height":0.030327214},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.015957447,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.007978723,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.013962766,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 2:45:14 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:45","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Shared Elasticsearch Sockets:","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Because","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"pcntl_fork()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"resetAfterFork()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"cURL","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"exceptions.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Supervisor Shutdown Deadlock:","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"In","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"reapChildren()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":", calling","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"pcntl_waitpid()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"without the","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"WNOHANG","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"flag makes it a blocking call. If one child process gets stuck (e.g., waiting on a network timeout), the parent supervisor will freeze indefinitely and completely ignore your 10-second graceful shutdown logic.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"(edited)","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 2:45:29 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:45","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"3.","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Non-Atomic Redis Locks:","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"The new","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"ReindexTargetStatsReporter","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"checks the lock with","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"get","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"and then creates it with","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"set","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":". Because the workers are truly parallel, they can both read","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"null","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"at the exact same microsecond and both push duplicate metrics to Datadog. This needs to be a single, atomic command (e.g.,","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"set","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"with","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"NX","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":").","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Vasil Vasilev","depth":16,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 2:56:52 PM","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:56 PM","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1 e добър коментар,","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 2:56:55 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:56","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2 е intentional,","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 2:57:50 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:57","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"3 също е intentional поради факта, че phpredis driver-a не поддържа set ex +nx параметри, и трябва да се пуснат две операции set + expire","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Lukas Kovalik","depth":16,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 3:07:16 PM","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"3:07 PM","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"ок, аз го пуснах пак през gemini","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 3:07:31 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"3:07","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"за третата точка обаче наистина ли няма подържка","depth":17,"on_screen":false,"role_description":"text"}]...
|
-4572867615118383068
|
-993693222112905130
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Today at 2:45:14 PM
2:45
1.
Shared Elasticsearch Sockets:
Because
pcntl_fork()
clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in
resetAfterFork()
(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and
cURL
exceptions.
2.
Supervisor Shutdown Deadlock:
In
reapChildren()
, calling
pcntl_waitpid()
without the
WNOHANG
flag makes it a blocking call. If one child process gets stuck (e.g., waiting on a network timeout), the parent supervisor will freeze indefinitely and completely ignore your 10-second graceful shutdown logic.
(edited)
Today at 2:45:29 PM
2:45
3.
Non-Atomic Redis Locks:
The new
ReindexTargetStatsReporter
checks the lock with
get
and then creates it with
set
. Because the workers are truly parallel, they can both read
null
at the exact same microsecond and both push duplicate metrics to Datadog. This needs to be a single, atomic command (e.g.,
set
with
NX
).
Vasil Vasilev
Today at 2:56:52 PM
2:56 PM
1 e добър коментар,
Today at 2:56:55 PM
2:56
2 е intentional,
Today at 2:57:50 PM
2:57
3 също е intentional поради факта, че phpredis driver-a не поддържа set ex +nx параметри, и трябва да се пуснат две операции set + expire
Lukas Kovalik
Today at 3:07:16 PM
3:07 PM
ок, аз го пуснах пак през gemini
Today at 3:07:31 PM
3:07
за третата точка обаче наистина ли няма подържка
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obtectXMlinbox (1294) - Mias kowlikSlimlZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~<> Codejiminny / app &17 Pull requests 336. AgentsThat is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavina amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page© ActionsQ WikiJY-2096LaKVLQ) ConversationLakyLakJIKATChange•FIxtnikolay-aclauaActivityMore8• Thu 28 May 16:20:38JiminnYinrede@ ThreadsleawddocDrafts & sent© Directories01Ah External connections# Starredolatform-backend…8 platform-inner-team@) Channels# backend# ai-chapten# alerts# bugs# confusion-dlinid# donut_time# enpineerine# general# happy_birthdayA infosec intemal all# infra-changest infrastructure del#ibu-team-info# jiminny-bg# olatform-team# platform-tickets# product launches"andom# releases# support# thank-yous# the peoole of fimill^ Direct messagesllivana Netceve. Vasil Vasilev Ef8. Stefka Stoyanova O88. Stoyan Tomov® Petko KashinskiQ Describe what you are looking for€. Vasil Vasilev EAdd canvas© Files& PinsVasil Vasilev I 3:11 PMpredis поддьржа set(Skey, Svalue. ['nx' = true, ex =60)c phpredis не ставаLukas Kovalik 3:11 PMтака май не работеше Sresult = Redis-set(StestKey, StestValue 'EX" Swl. "NX"): а така ла Sresult = Redisuset(StestKey, StestValue l'nx' 'ex' => Stll):wsilasileukhaemЗO0OТО ПDOОВХИ НеСКHLukas Kovallk 3.7PMили обоитноVasil Vasilev Il 3:12 PMобратното може да eLukas Kovalik 3:12PMможе и да бръкамVasil Vasilev # 3:12 PMв кода нмаSlockAcquired - Redis: :set(self:: POLLING_LOCK_KEY, json_encode(SlockData), 'EX*, self:: LOCK_TTL_SECONOS, *NX*):значи пьрвото работиuukas Kovalnk rakiorда и в арр/Services/Crm/Hubspot/Client.php:103Vasil Vasiley 3:14 pMUKAS KOVJIKKeGPMwerwwensm.wewbBereMulMnosEhcwcooucnoneahhieethhormertokVasil Vasilev B 3:17 PMLukas Kovalik 3:17PMдано няма нещо промененсVasil Vasilev # 3:17 PMще си го оставя както eUnkas Kovalllk 2-18 prок, мисля че е само ideWlwvacllew 22ko1МІЛИІНА АЗТОМАИНЙ ОЛАЛИННЯТ НА A ЛОЯМресетването на ЕС лескоиптора обаче е много алекратен коментар.Message Vasil Vasilev In a meeting • Google Calendar...
|
85841
|
NULL
|
NULL
|
NULL
|
|
85842
|
2944
|
11
|
2026-05-28T13:20:38.937768+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974438937_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 2 new items - S Vasil Vasilev (DM) - Jiminny Inc - 2 new items - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Today at 2:45:14 PM
2:45
1.
Shared Elasticsearch Sockets:
Because
pcntl_fork()
clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in
resetAfterFork()
(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and
cURL
exceptions.
2....
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"general","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"happy_birthday","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infosec_internal_all","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infrastructure_dev","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"jbu-team-info","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-team","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"random","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"support","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Iliyana Netseva","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":16,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Stefka Stoyanova","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Stoyan Tomov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06458333,"height":0.02},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Petko Kashinski","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.072222225,"height":0.02},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.07361111,"height":0.0044444446},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Todor Stamatov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.072222225,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.07986111,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Ves","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.016666668,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Mira","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.021527778,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06875,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"James Graham","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06666667,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.061805554,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"you","depth":15,"bounds":{"left":0.6354167,"top":0.0,"width":0.013194445,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.045833334,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.024305556,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Add canvas","depth":10,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Add canvas","depth":12,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Pins","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Pins","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":9,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 2:45:14 PM","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:45","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"1.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Shared Elasticsearch Sockets:","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Because","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"pcntl_fork()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"resetAfterFork()","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"cURL","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"exceptions.","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"2.","depth":16,"on_screen":false,"role_description":"text"}]...
|
-8079353766350881471
|
-2072235342014244122
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Today at 2:45:14 PM
2:45
1.
Shared Elasticsearch Sockets:
Because
pcntl_fork()
clones file descriptors, both child processes will share the exact same HTTP/TCP socket for Elasticsearch. Since you didn’t reset the ES client in
resetAfterFork()
(like you did for Redis and DB), the parallel workers will collide at the network layer, causing corrupted data and
cURL
exceptions.
2.
iTerm2ShellEditViewSessionScriptsProfilesWindowHelp(ah]-zshDOCKER₴81DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%85ec2-user@ip-10-30-129-...100% <78 • Thu 28 May 16:20:38181ec2-user@ip-10-30-140-…₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85841
|
2945
|
13
|
2026-05-28T13:20:33.156430+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974433156_m2.jpg...
|
Slack
|
Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.015292553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"}]...
|
-971148781092092033
|
-8138964766819926409
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obtectXM inbox (1,734) - lukas.kovalik@jiminZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page<> Codejiminny / app &17 Pull requests 336. Agents© ActionsQ wikiJY-2096I1 OpenLaKVLQ) ConversationLakyLakJIKATChange•FIxt_Lak'nikolay-aclauaHomeActivityMoreJiminnY ….inrede@ Threads6 HuddlesDrafts & sent© Directories01Ah External connections# Starredolatform-backend…8 platform-inner-team@) Channels# backend# ai-chapten# alerts# bugs# confusion-dlinid# donut_time# engineering# general# happy_birthdayA infosec intemal all# infra-changest infrastructure del#ibu-team-info# jiminny-bg# platform-team# platform-tickets# product launches"endom# releases# support# thank-yous# the peoole of fimill^ Direct messages€. Vasil Vasilev E(T. lliyana Netsevaf8. Stefka Stoyanova O88. Stoyan Tomov® Petko KashinskiInu co woy to.cuisQ Describe what you are looking for(L.lliyana NetsevaNoA0d canvisThis conversation is just between @lliyana Netseva and you. Check out their pronle to learn more about them.View Profilelukas Kovalik 12-32 pvЗЛОЯВеН, ИМАШІЛИ МИНУТКАvanat Ne cevatteokolod chaeh svonddeninshiesLukas Kovalik 2.5yPMздрасти, да но мисля че няма нужда вече"wxwececьecohh Tow ocwex.hoshsnhnoorKeпод този кейс имам предвид https://jiminny.atlassian.net/browse/SRD-6881ira dloud* Bue se 6edl in ara cloutifOn demandl Transcrintion in saved search disappearReady for customer8 Lukas Kovalik (you)As of today at 2:53 PM•виж коментари и ако тояова нешо друго може да се чуемTlvantNe sevathopvividah kakvo si napisal. neshtoto koeto mi e stranno e che razlikata meidu tova koeto pravi ta i tova koeto si napisal ti e natiskaneto na enter-a za da izoulni search«:popravi me ako cresh.Lukas Kovalik 2:57PMла, или лупатада се търси nо transcriptlliyana Netseva 3:04 PMima li prichina tova da e napraveno po tozi nachin ili prosto taka e napraveno nakogaLukas Kovalik 3.05 PMне знам, композитен филтьр е може би трябва да си настроиш нещата и после да направиш една заявка (Asked by например)тука не сьм сигурен, по-скоро е за продуктlliyana Netseva 4:00 PMok, thank you AeMessage Iliyana Netseva...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85840
|
2944
|
10
|
2026-05-28T13:20:33.048425+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974433048_m1.jpg...
|
Slack
|
Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"on_screen":true,"role_description":"text"}]...
|
-8206206894589548001
|
-5833050220622561673
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
iTerm2ShellEditViewSessionScriptsProfilesWindowHelp(ah]-zshDOCKER881DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%85ec2-user@ip-10-30-129-...100% <478 • Thu 28 May 16:20:32181ec2-user@ip-10-30-140-…₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
85838
|
NULL
|
NULL
|
NULL
|
|
85839
|
2945
|
12
|
2026-05-28T13:20:19.467569+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974419467_m2.jpg...
|
Slack
|
Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Iliyana Netseva (DM) - Jiminny Inc - 3 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Iliyana Netseva
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Add and Edit Channel Tabs
Canvas
List
Folder
Iliyana Netseva
Iliyana Netseva
This conversation is just between
@Iliyana Netseva
@Iliyana Netseva
and you. Check out their profile to learn more about them.
View Profile
Jump to date
Lukas Kovalik
Today at 12:32:31 PM
12:32 PM
здравей, имаш ли минутка
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Iliyana Netseva
Today at 2:51:31 PM
2:51 PM
okolo 4 chasa svoboden li shte si ?
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 2:52:21 PM
2:52 PM
здрасти, да но мисля че няма нужда вече
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:52:47 PM
2:52
чухме се със Стоян и той беше запознат и по този кейс
React with white_check_mark...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.015292553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.024268618,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54089093,"top":0.18994413,"width":0.020279255,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.044215426,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":25,"bounds":{"left":0.54521275,"top":0.28411812,"width":0.058843084,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.04454787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":18,"bounds":{"left":0.54521275,"top":0.3064645,"width":0.04155585,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":15,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54521275,"top":0.35913807,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.022273935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54488033,"top":0.38148445,"width":0.019614361,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.012300532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54488033,"top":0.4038308,"width":0.00930851,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.010638298,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":3,"bounds":{"left":0.54521275,"top":0.42617717,"width":0.00731383,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54454786,"top":0.44852355,"width":0.032247342,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.025265958,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54521275,"top":0.4708699,"width":0.022273935,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":15,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.025930852,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54488033,"top":0.49321628,"width":0.022938829,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"general","depth":15,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.016289894,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54488033,"top":0.51556265,"width":0.013297873,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"happy_birthday","depth":15,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.033909574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":13,"bounds":{"left":0.54521275,"top":0.53790903,"width":0.030917553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infosec_internal_all","depth":15,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.041888297,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":19,"bounds":{"left":0.54355055,"top":0.5602554,"width":0.040226065,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":15,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.029587766,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.5826017,"width":0.02825798,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infrastructure_dev","depth":15,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.040226065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":17,"bounds":{"left":0.54355055,"top":0.6049481,"width":0.038896278,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jbu-team-info","depth":15,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.029920213,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.6272945,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":15,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.023271276,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54355055,"top":0.64964086,"width":0.021609042,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-team","depth":15,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.03158245,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54521275,"top":0.67198724,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":15,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.034906916,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.6943336,"width":0.031914894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":15,"bounds":{"left":0.5422208,"top":0.71668,"width":0.03856383,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.71668,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.71668,"width":0.03557181,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"random","depth":15,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.016954787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54421544,"top":0.7390263,"width":0.014960106,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":15,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.0016622341,"height":0.014365523}},{"char_start":1,"char_count":7,"bounds":{"left":0.54388297,"top":0.7613727,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"support","depth":15,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.017287234,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54454786,"top":0.78371906,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":15,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.024601065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54421544,"top":0.80606544,"width":0.022606382,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":15,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.045212764,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":20,"bounds":{"left":0.54421544,"top":0.8284118,"width":0.04720745,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":15,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.027593086,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.0033244682,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5455452,"top":0.8810854,"width":0.024268618,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Iliyana Netseva","depth":16,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.03324468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":14,"bounds":{"left":0.54355055,"top":0.9034318,"width":0.031914894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Stefka Stoyanova","depth":15,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.037898935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54488033,"top":0.92577815,"width":0.03523936,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Stoyan Tomov","depth":15,"bounds":{"left":0.5422208,"top":0.9481245,"width":0.030917553,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.9481245,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":11,"bounds":{"left":0.54488033,"top":0.9481245,"width":0.027925532,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Petko Kashinski","depth":15,"bounds":{"left":0.5422208,"top":0.97047085,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.97047085,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":14,"bounds":{"left":0.54521275,"top":0.97047085,"width":0.03158245,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":15,"bounds":{"left":0.5422208,"top":0.9928172,"width":0.03523936,"height":0.0031923384},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Todor Stamatov","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.034574468,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.038231384,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Ves","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.007978723,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Mira","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.010305851,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.032912236,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"James Graham","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.031914894,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.029587766,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"you","depth":15,"bounds":{"left":0.5744681,"top":0.9952115,"width":0.0063164895,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.021941489,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":15,"bounds":{"left":0.5422208,"top":0.9952115,"width":0.011635638,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":9,"bounds":{"left":0.60206115,"top":0.09177973,"width":0.030917553,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":11,"bounds":{"left":0.61136967,"top":0.10055866,"width":0.018949468,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.61136967,"top":0.10055866,"width":0.0039893617,"height":0.012769354}},{"char_start":1,"char_count":7,"bounds":{"left":0.61535907,"top":0.10055866,"width":0.014960106,"height":0.012769354}}],"role_description":"text"},{"role":"AXRadioButton","text":"Add canvas","depth":10,"bounds":{"left":0.63397604,"top":0.09177973,"width":0.034242023,"height":0.030327214},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Add canvas","depth":12,"bounds":{"left":0.64328456,"top":0.10055866,"width":0.022273935,"height":0.012769354},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.64328456,"top":0.10055866,"width":0.0033244682,"height":0.012769354}},{"char_start":1,"char_count":9,"bounds":{"left":0.6462766,"top":0.10055866,"width":0.019281914,"height":0.012769354}}],"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":9,"bounds":{"left":0.66921544,"top":0.09177973,"width":0.010970744,"height":0.030327214},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.015957447,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.007978723,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":9,"bounds":{"left":0.59640956,"top":0.0518755,"width":0.013962766,"height":0.0007980846},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Iliyana Netseva","depth":14,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Iliyana Netseva","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"This conversation is just between","depth":14,"bounds":{"left":0.60339093,"top":0.15003991,"width":0.08676862,"height":0.016759777},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.60339093,"top":0.15003991,"width":0.0033244682,"height":0.016759777}},{"char_start":1,"char_count":32,"bounds":{"left":0.60671544,"top":0.15003991,"width":0.08211436,"height":0.016759777}}],"role_description":"text"},{"role":"AXLink","text":"@Iliyana Netseva","depth":14,"bounds":{"left":0.69015956,"top":0.14924182,"width":0.045212764,"height":0.018355945},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"@Iliyana Netseva","depth":15,"bounds":{"left":0.69082445,"top":0.15003991,"width":0.043882977,"height":0.016759777},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.69082445,"top":0.15003991,"width":0.004986702,"height":0.016759777}},{"char_start":1,"char_count":15,"bounds":{"left":0.69547874,"top":0.15003991,"width":0.039228722,"height":0.016759777}}],"role_description":"text"},{"role":"AXStaticText","text":"and you. Check out their profile to learn more about them.","depth":14,"bounds":{"left":0.73537236,"top":0.15003991,"width":0.1505984,"height":0.016759777},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"View Profile","depth":13,"bounds":{"left":0.60339093,"top":0.1811652,"width":0.035904255,"height":0.02952913},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Jump to date","depth":14,"bounds":{"left":0.7849069,"top":0.23383878,"width":0.025265958,"height":0.023144454},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.6180186,"top":0.26496407,"width":0.030917553,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":15,"bounds":{"left":0.64893615,"top":0.26656026,"width":0.0026595744,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 12:32:31 PM","depth":15,"bounds":{"left":0.6515958,"top":0.26895452,"width":0.017287234,"height":0.011971269},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:32 PM","depth":16,"bounds":{"left":0.6515958,"top":0.26895452,"width":0.017287234,"height":0.011971269},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"здравей, имаш ли минутка","depth":16,"bounds":{"left":0.6180186,"top":0.28411812,"width":0.061835106,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":17,"on_screen":false,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Iliyana Netseva","depth":15,"bounds":{"left":0.6180186,"top":0.3064645,"width":0.034574468,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":15,"bounds":{"left":0.65226066,"top":0.30806065,"width":0.0026595744,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 2:51:31 PM","depth":15,"bounds":{"left":0.6549202,"top":0.3104549,"width":0.015292553,"height":0.011971269},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:51 PM","depth":16,"bounds":{"left":0.6549202,"top":0.3104549,"width":0.015292553,"height":0.011971269},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"okolo 4 chasa svoboden li shte si ?","depth":16,"bounds":{"left":0.6180186,"top":0.3256185,"width":0.07480053,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":17,"on_screen":false,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.6180186,"top":0.34796488,"width":0.030917553,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":15,"bounds":{"left":0.64893615,"top":0.34956107,"width":0.0026595744,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 2:52:21 PM","depth":15,"bounds":{"left":0.6515958,"top":0.3519553,"width":0.014960106,"height":0.011971269},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:52 PM","depth":16,"bounds":{"left":0.6515958,"top":0.3519553,"width":0.014960106,"height":0.011971269},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"здрасти, да но мисля че няма нужда вече","depth":16,"bounds":{"left":0.6180186,"top":0.36711892,"width":0.09541223,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":17,"on_screen":false,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Today at 2:52:47 PM","depth":16,"bounds":{"left":0.60738033,"top":0.3934557,"width":0.007978723,"height":0.011971269},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:52","depth":17,"bounds":{"left":0.60738033,"top":0.3934557,"width":0.007978723,"height":0.011971269},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"чухме се със Стоян и той беше запознат и по този кейс","depth":16,"bounds":{"left":0.6180186,"top":0.39106146,"width":0.12699468,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":17,"on_screen":false,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6438841771287680721
|
-1280828110741798570
|
visual_change
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Iliyana Netseva
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Add canvas
Add canvas
Add and Edit Channel Tabs
Canvas
List
Folder
Iliyana Netseva
Iliyana Netseva
This conversation is just between
@Iliyana Netseva
@Iliyana Netseva
and you. Check out their profile to learn more about them.
View Profile
Jump to date
Lukas Kovalik
Today at 12:32:31 PM
12:32 PM
здравей, имаш ли минутка
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Iliyana Netseva
Today at 2:51:31 PM
2:51 PM
okolo 4 chasa svoboden li shte si ?
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 2:52:21 PM
2:52 PM
здрасти, да но мисля че няма нужда вече
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:52:47 PM
2:52
чухме се със Стоян и той беше запознат и по този кейс
React with white_check_mark
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obtectXMlinbox (1224) - Mias kowstikSlimZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page<> Codejiminny / app &17 Pull requests 336. Agents© ActionsQ wikiJY-2096I1 OpenLaKVLQ) ConversationLakyLakJIKATChange•FIxt_Lak'nikolay-aclauaHomeActivityMoreJiminnY ….inrede@ Threads6 HuddlesDrafts & sent© Directories01Ah External connections# Starredolatform-backend…8 platform-inner-team@) Channels# backend# ai-chapten# alerts# bugs# confusion-dlinid# donut_time# engineering# general# happy_birthdayA infosec intemal all# infra-changest infrastructure del#ibu-team-info# jiminny-bg# olatform-team# platform-tickets# product launches"endom# releases# support# thank-yous# the _people_of jimi.…^ Direct messages€. Vasil Vasilev =(T. lliyana Netsevaf8. Stefka Stoyanova O88. Stoyan Tomov® Petko KashinskiInu co woy to.cu.Q Describe what you are looking for(L.lliyana NetsevaNoA0d canvisThis conversation is just between @lliyana Netseva and you. Check out their pronle to learn more about them.View Profilelukas Kovalik 12-32 pvЗЛОЯВеН, ИМАШІЛИ МИНУТКАvanat Ne cevatteokolod chaeh svonddeninshiesLukas Kovalik 2.5yPMздрасти, да но мисля че няма нужда вече"wxwececьecohh Tow ocwex.hoshsnhnoorKeпод този кейс имам предвид https://jiminny.atlassian.net/browse/SRD-6881ira dloud* Bue se 6edl in ara cloutifOn demandl Transcrintion in saved search disappearReady for customer8 Lukas Kovalik (you)As of today at 2:53 PM•виж коментари и ако тояова нешо друго може да се чуемTlvantNe sevathopvividah kakvo si napisal. neshtoto koeto mi e stranno e che razlikata meidu tova koeto pravi ta i tova koeto si napisal ti e natiskaneto na enter-a za da izoulni search«:popravi me ako cresh.Lukas Kovalik 2:57PMла, или лупатада се търси nо transcriptlliyana Netseva 3:04 PMima li prichina tova da e napraveno po tozi nachin ili prosto taka e napraveno nakogaLukas Kovalik 3.05 PMне знам, композитен филтьр е може би трябва да си настроиш нещата и после да направиш една заявка (Asked by например)тука не сьм сигурен, по-скоро е за продуктlliyana Netseva 4:00 PMok, thank you AeMessage Iliyana Netseva...
|
85837
|
NULL
|
NULL
|
NULL
|
|
85838
|
2944
|
9
|
2026-05-28T13:20:17.306507+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974417306_m1.jpg...
|
Slack
|
releases (Channel) - Jiminny Inc - 4 new items - S releases (Channel) - Jiminny Inc - 4 new items - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Files
Files
Bookmarks
Bookmarks
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
CircleCI
APP
Today at 9:27:04 AM
9:27 AM
Deployment Successful! tada emoji
Deployment Successful!
Project
: app
When
: 05/28/2026 06:27:03
Tag
:
View Job
View Job
GitHub
APP
Today at 10:50:39 AM
10:50 AM
20 new commits
20 new commits
pushed to
master
master
by
yalokin-jiminny
yalokin-jiminny
891eb72c
891eb72c
- JY-20855 | Add MCP ES - summary
1b8845ee
1b8845ee
- JY-20855 | Add MCP ES - action_items
18b9e3df
18b9e3df
- JY-20855 | Add MCP ES - key_points
1fd201fa
1fd201fa
- JY-20855 | Add MCP ES - notes
99ec572d
99ec572d
- JY-20855 | Add MCP ES - moments
Show more
jiminny/app
jiminny/app
|
Added by
GitHub
GitHub
GitHub
APP
Today at 11:09:25 AM
11:09 AM
1 new commit
1 new commit
pushed to
master
master
by
yalokin-jiminny
yalokin-jiminny
96465d0b
96465d0b
- Fix stage profile for remote commands run
jiminny/app
jiminny/app
|
Added by
GitHub
GitHub
CircleCI
APP
Today at 11:16:27 AM
11:16 AM
Deployment Successful! tada emoji
Deployment Successful!
Project
: app
When
: 05/28/2026 08:16:27
Tag
:
View Job...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"general","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"happy_birthday","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infosec_internal_all","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"infrastructure_dev","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"jbu-team-info","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-team","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"random","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"support","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Iliyana Netseva","depth":16,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Stefka Stoyanova","depth":15,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Stoyan Tomov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06458333,"height":0.02},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Petko Kashinski","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.072222225,"height":0.02},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.07361111,"height":0.0044444446},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Todor Stamatov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.072222225,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.07986111,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Ves","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.016666668,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Mira","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.021527778,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06875,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"James Graham","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.06666667,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Lukas Kovalik","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.061805554,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"you","depth":15,"bounds":{"left":0.6354167,"top":0.0,"width":0.013194445,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.045833334,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":15,"bounds":{"left":0.56805557,"top":0.0,"width":0.024305556,"height":0.0011111111},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Bookmarks","depth":9,"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Bookmarks","depth":11,"on_screen":true,"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":9,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":9,"on_screen":true,"role_description":"text"},{"role":"AXPopUpButton","text":"Jump to date","depth":15,"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"CircleCI","depth":16,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"APP","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 9:27:04 AM","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"9:27 AM","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXHeading","text":"Deployment Successful! tada emoji","depth":16,"on_screen":false,"role_description":"heading"},{"role":"AXStaticText","text":"Deployment Successful!","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Project","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":": app","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"When","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":": 05/28/2026 06:27:03","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Tag","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":":","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"View Job","depth":17,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"View Job","depth":19,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"GitHub","depth":16,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"APP","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 10:50:39 AM","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"10:50 AM","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"20 new commits","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"20 new commits","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"pushed to","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"master","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"master","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"by","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"yalokin-jiminny","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"yalokin-jiminny","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"891eb72c","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"891eb72c","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- JY-20855 | Add MCP ES - summary","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"1b8845ee","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1b8845ee","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- JY-20855 | Add MCP ES - action_items","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"18b9e3df","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"18b9e3df","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- JY-20855 | Add MCP ES - key_points","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"1fd201fa","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1fd201fa","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- JY-20855 | Add MCP ES - notes","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"99ec572d","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"99ec572d","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- JY-20855 | Add MCP ES - moments","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Show more","depth":18,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"jiminny/app","depth":18,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"jiminny/app","depth":19,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"|","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Added by","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"GitHub","depth":18,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"GitHub","depth":19,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"GitHub","depth":16,"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"APP","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"Today at 11:09:25 AM","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"11:09 AM","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"1 new commit","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1 new commit","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"pushed to","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"master","depth":17,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"master","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"by","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"yalokin-jiminny","depth":16,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"yalokin-jiminny","depth":17,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"96465d0b","depth":19,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"96465d0b","depth":20,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"- Fix stage profile for remote commands run","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"jiminny/app","depth":18,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"jiminny/app","depth":19,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"|","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"Added by","depth":18,"on_screen":false,"role_description":"text"},{"role":"AXLink","text":"GitHub","depth":18,"on_screen":false,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"GitHub","depth":19,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"CircleCI","depth":16,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"APP","depth":16,"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"","depth":16,"on_screen":true,"role_description":"text"},{"role":"AXLink","text":"Today at 11:16:27 AM","depth":16,"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"11:16 AM","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXHeading","text":"Deployment Successful! tada emoji","depth":16,"on_screen":true,"role_description":"heading"},{"role":"AXStaticText","text":"Deployment Successful!","depth":18,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Project","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":": app","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"When","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":": 05/28/2026 08:16:27","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Tag","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":":","depth":17,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"View Job","depth":17,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4363628649040064245
|
-7613132153111432454
|
click
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
Stoyan Tomov
Petko Kashinski
Galya Dimitrova
Todor Stamatov
Steliyan Georgiev
Ves
Mira
Nikolay Yankov
James Graham
Lukas Kovalik
you
Jira Cloud
Toast
Messages
Messages
Files
Files
Bookmarks
Bookmarks
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
CircleCI
APP
Today at 9:27:04 AM
9:27 AM
Deployment Successful! tada emoji
Deployment Successful!
Project
: app
When
: 05/28/2026 06:27:03
Tag
:
View Job
View Job
GitHub
APP
Today at 10:50:39 AM
10:50 AM
20 new commits
20 new commits
pushed to
master
master
by
yalokin-jiminny
yalokin-jiminny
891eb72c
891eb72c
- JY-20855 | Add MCP ES - summary
1b8845ee
1b8845ee
- JY-20855 | Add MCP ES - action_items
18b9e3df
18b9e3df
- JY-20855 | Add MCP ES - key_points
1fd201fa
1fd201fa
- JY-20855 | Add MCP ES - notes
99ec572d
99ec572d
- JY-20855 | Add MCP ES - moments
Show more
jiminny/app
jiminny/app
|
Added by
GitHub
GitHub
GitHub
APP
Today at 11:09:25 AM
11:09 AM
1 new commit
1 new commit
pushed to
master
master
by
yalokin-jiminny
yalokin-jiminny
96465d0b
96465d0b
- Fix stage profile for remote commands run
jiminny/app
jiminny/app
|
Added by
GitHub
GitHub
CircleCI
APP
Today at 11:16:27 AM
11:16 AM
Deployment Successful! tada emoji
Deployment Successful!
Project
: app
When
: 05/28/2026 08:16:27
Tag
:
View Job
iTerm2ShellEditViewSessionScriptsProfilesWindowHelp(ah]-zshDOCKER881DEV (docker)₴82-zshscreenpipe"84-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%X5ec2-user@ip-10-30-129-...100% <78• Thu 28 May 16:20:17181ec2-user@ip-10-30-140-…₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85837
|
2945
|
11
|
2026-05-28T13:20:16.268195+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974416268_m2.jpg...
|
Slack
|
! releases (Channel) - Jiminny Inc - 3 new items - ! releases (Channel) - Jiminny Inc - 3 new items - Slack...
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova...
|
[{"role":"AXPopUpButton","text [{"role":"AXPopUpButton","text":"Switch workspaces… (Jiminny Inc) Has new messages","depth":6,"bounds":{"left":0.5056516,"top":0.058260176,"width":0.011968086,"height":0.028731046},"on_screen":true,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":6,"bounds":{"left":0.50299203,"top":0.10055866,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":8,"bounds":{"left":0.50664896,"top":0.13806863,"width":0.009973404,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":6,"bounds":{"left":0.50299203,"top":0.15482841,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":8,"bounds":{"left":0.50764626,"top":0.19233839,"width":0.007978723,"height":0.0103751},"on_screen":true,"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":6,"bounds":{"left":0.50299203,"top":0.20909816,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":8,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.012965426,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5053192,"top":0.24660814,"width":0.0026595744,"height":0.011173184}},{"char_start":1,"char_count":7,"bounds":{"left":0.50764626,"top":0.24660814,"width":0.010638298,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":6,"bounds":{"left":0.50299203,"top":0.26336792,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":8,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0076462766,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50797874,"top":0.3008779,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5099734,"top":0.3008779,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":6,"bounds":{"left":0.50299203,"top":0.31763768,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":8,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.008643617,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.35514766,"width":0.0019946808,"height":0.011173184}},{"char_start":1,"char_count":4,"bounds":{"left":0.5093085,"top":0.35514766,"width":0.0066489363,"height":0.011173184}}],"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":6,"bounds":{"left":0.50299203,"top":0.3719074,"width":0.017287234,"height":0.054269753},"on_screen":true,"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":8,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.008976064,"height":0.0103751},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.50731385,"top":0.4094174,"width":0.0033244682,"height":0.011173184}},{"char_start":1,"char_count":3,"bounds":{"left":0.5106383,"top":0.4094174,"width":0.0056515955,"height":0.011173184}}],"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":13,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.10055866,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5405585,"top":0.10055866,"width":0.015292553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":13,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.01761968,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.12290503,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.5398936,"top":0.12290503,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":13,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.1452514,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54089093,"top":0.1452514,"width":0.014295213,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":13,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.02925532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.16759777,"width":0.003656915,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5405585,"top":0.16759777,"width":0.025265958,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"1","depth":13,"bounds":{"left":0.5884308,"top":0.16839585,"width":0.0026595744,"height":0.012769354},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":13,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.024268618,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5369016,"top":0.18994413,"width":0.0039893617,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54089093,"top":0.18994413,"width":0.020279255,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-backend-engineers","depth":15,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.044215426,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.28411812,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":25,"bounds":{"left":0.54521275,"top":0.28411812,"width":0.058843084,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":15,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.04454787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.3064645,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":18,"bounds":{"left":0.54521275,"top":0.3064645,"width":0.04155585,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":15,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.018949468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.35913807,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54521275,"top":0.35913807,"width":0.015957447,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":15,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.022273935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.38148445,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54488033,"top":0.38148445,"width":0.019614361,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":15,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.012300532,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4038308,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54488033,"top":0.4038308,"width":0.00930851,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"bugs","depth":15,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.010638298,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.42617717,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":3,"bounds":{"left":0.54521275,"top":0.42617717,"width":0.00731383,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":15,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.44852355,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54454786,"top":0.44852355,"width":0.032247342,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"donut_time","depth":15,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.025265958,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.4708699,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54521275,"top":0.4708699,"width":0.022273935,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":15,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.025930852,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.49321628,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":10,"bounds":{"left":0.54488033,"top":0.49321628,"width":0.022938829,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"general","depth":15,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.016289894,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.51556265,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54488033,"top":0.51556265,"width":0.013297873,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"happy_birthday","depth":15,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.033909574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.53790903,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":13,"bounds":{"left":0.54521275,"top":0.53790903,"width":0.030917553,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infosec_internal_all","depth":15,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.041888297,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5602554,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":19,"bounds":{"left":0.54355055,"top":0.5602554,"width":0.040226065,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":15,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.029587766,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.5826017,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.5826017,"width":0.02825798,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"infrastructure_dev","depth":15,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.040226065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6049481,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":17,"bounds":{"left":0.54355055,"top":0.6049481,"width":0.038896278,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jbu-team-info","depth":15,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.029920213,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6272945,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54355055,"top":0.6272945,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":15,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.023271276,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.64964086,"width":0.0013297872,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54355055,"top":0.64964086,"width":0.021609042,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-team","depth":15,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.03158245,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.67198724,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.54521275,"top":0.67198724,"width":0.028590426,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":15,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.034906916,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.6943336,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.6943336,"width":0.031914894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":15,"bounds":{"left":0.5422208,"top":0.71668,"width":0.03856383,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.71668,"width":0.0029920214,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54521275,"top":0.71668,"width":0.03557181,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"random","depth":15,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.016954787,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7390263,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":5,"bounds":{"left":0.54421544,"top":0.7390263,"width":0.014960106,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":15,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.018284574,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.7613727,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":7,"bounds":{"left":0.54421544,"top":0.7613727,"width":0.016289894,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"support","depth":15,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.017287234,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.78371906,"width":0.0023271276,"height":0.014365523}},{"char_start":1,"char_count":6,"bounds":{"left":0.54454786,"top":0.78371906,"width":0.01462766,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":15,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.024601065,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.80606544,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":9,"bounds":{"left":0.54421544,"top":0.80606544,"width":0.022606382,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":15,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.045212764,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8284118,"width":0.0019946808,"height":0.014365523}},{"char_start":1,"char_count":20,"bounds":{"left":0.54421544,"top":0.8284118,"width":0.04720745,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Iliyana Netseva","depth":15,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.034574468,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.8810854,"width":0.0016622341,"height":0.014365523}},{"char_start":1,"char_count":14,"bounds":{"left":0.54388297,"top":0.8810854,"width":0.032579787,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":15,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.027593086,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.9034318,"width":0.0033244682,"height":0.014365523}},{"char_start":1,"char_count":12,"bounds":{"left":0.5455452,"top":0.9034318,"width":0.024268618,"height":0.014365523}}],"role_description":"text"},{"role":"AXStaticText","text":"Stefka Stoyanova","depth":15,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.037898935,"height":0.014365523},"on_screen":true,"lines":[{"char_start":0,"char_count":1,"bounds":{"left":0.5422208,"top":0.92577815,"width":0.0026595744,"height":0.014365523}},{"char_start":1,"char_count":15,"bounds":{"left":0.54488033,"top":0.92577815,"width":0.03523936,"height":0.014365523}}],"role_description":"text"}]...
|
8705208610414305968
|
-8108529168268705934
|
visual_change
|
hybrid
|
NULL
|
Switch workspaces… (Jiminny Inc) Has new messages
Switch workspaces… (Jiminny Inc) Has new messages
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
1
Directories
platform-backend-engineers
platform-inner-team
backend
ai-chapter
alerts
bugs
confusion-clinic
donut_time
engineering
general
happy_birthday
infosec_internal_all
infra-changes
infrastructure_dev
jbu-team-info
jiminny-bg
platform-team
platform-tickets
product_launches
random
releases
support
thank-yous
the_people_of_jiminny
Iliyana Netseva
Vasil Vasilev
Stefka Stoyanova
sluckcolVICh© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object erroreweorikiy deleted obtectXM inbox (1,734) - lukas.kovalik@jiminZ (JY-20979) Resoive PHP 8.5.5 depPiatform Sprint 5 Q2 - Platform TeJiminmy(SRD-6881) (On demand) Transc8 Sona Subramanian at 27/05/2021Ihaos Netcoya at 27/05/2026.188 Jiminay4 Now Th!RotonWindowHelp= github.com/jiminny/app/pull/12121v Gooc e GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => seLT::LOCK-TTL.SECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino almicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get , both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize page<> Codejiminny / app C17 Pull requests 336. Agents© ActionsQ wikiJY-2096I1 OpenLaKVLQ) ConversationLakyLakJIKATChange•FIxtnikolay-aclauaHomeActivityMoreQ Describe what you are looking forJiminnY* #releasesinrede@ Threadsleaiwddoee MessagertriesBookmarksDeployment Successful!Prolect aopWhen:05/748/40260891672Activity 6-2%o Dмlliyana Netsevaok, thank you A820 mins (1Vasil Vasilevресетването на ЕС дескриптора обаче ємного злекватен коментат12222PMmits pushed to master by LakyLak53 mins (21) - JY-20915 fix missing headera) - Merge branch'master into JY-20915-fix-missing-header-text-relay9) - Merge pull request #12136 from jiminny/JY-20915-fix-missing-header-Stetka StovanovaXoBPMGизвинявай, че така станаP 12:53PMat Successful!When: 05/28/2026 09:53:141 Stoyan Tomov1:17 PMи имим и ди доолвя още нешо ком негоApproved Toast> 3:14 PMnmits pushed to master by TodorStamatowJiminny.Nar Rowor ny kemd10-24 AM 2) - JY-208020: fix code smells6.Moros hranch"mactarinta.lY.209020.aladloma.room.intaorahon1) - JY-208020: fx implementation3) - JY-208020: add task resolving. fix crm prospect resolvingKcwashmntrouпо скоро да ми пише за да видим далище го планираме•/app Added by GitHubP 3:40 PMat SuccessfullCL Petko Kashinckil# the _people_of jimi.…^ Direct messages(T. lliyana Netseva8. Vasil Vasilev Ef8. Stefka Stoyanova O88. Stoyan Tomov® Petko KashinskiWhen: 05/28/2026 12:40:38Tag10 AMView JobMessage #releases+ Aa8 22Inu co moy to.cu.l20$...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85836
|
2945
|
10
|
2026-05-28T13:19:51.099821+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974391099_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.14245346,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
8345499037299352065
|
-9167764153827839868
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said...
|
85834
|
NULL
|
NULL
|
NULL
|
|
85835
|
2944
|
8
|
2026-05-28T13:19:50.080751+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974390080_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt
Gemini said
Gemini said
I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:
UpdateProcessManagerTest.php
.
Because the actual source files (such as
UpdateProcessManager.php
or
ReindexTargetStatsReporter.php
) are not included in the snippet, I cannot analyze them for potential issues.
If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.
Good response
Bad response
Share & export
Copy
Show more options...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the newly added test","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you explicitly mock the","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and set an expectation for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$batchStatusManager","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->once())->method(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->with(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"However, later in the same test, you instantiate","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"manually and explicitly call:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"$processor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->setUpdateTarget(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"self","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"::UPDATE_TARGET);","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager::setUpdateTarget()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"internally forwards that call to the underlying","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"BatchStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", your expectation passes. But if it does","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"not","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"forward it during that setter call (and instead calls it during","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"doUpdateEntitiesChunk","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), the test might be passing for the wrong reason or could break if the internal implementation changes.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"2. Inconsistent Environment Configuration in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In the new test, you instantiate the processor manually using","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"new UpdateProcessManager(...)","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"instead of using the updated","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper method.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"By bypassing","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", you lose the centralized setup. If the constructor requirements for","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"change in the future, this test will break and require manual updating, whereas tests using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"will be insulated from that change.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Refactor","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to utilize a slightly modified or parameterized version of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to keep the test suite DRY (Don't Repeat Yourself).","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"3. Tight Coupling to Log Strategies (withAnyArgs)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3. Tight Coupling to Log Strategies (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"In","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the precise log assertions from","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"were replaced with:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":18,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Log::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'info'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();\nLog::shouldReceive(","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'debug'","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")->withAnyArgs();","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Using","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"\"[ EsUpdateProcessManager ] Finished updating entities in ES\"","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), these tests will still pass.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Recommendation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Instead of completely silencing the logger with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"withAnyArgs()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", use","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"with()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that specific key tracking or lifecycle messages are still generated.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"4. Risks with","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Default Value (","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes = 0","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The helper method signature was changed to","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"private function prepareStatusManager(int $invokeTimes = 0): void","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"The Issue:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"When","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$invokeTimes","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"is","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", it sets an explicit expectation that","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"should","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"never","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"be called:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"PHP","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Download code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy code","depth":19,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"else","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"{","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$batchStatusManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->expects(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$this","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"->never())->method(","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'setUpdateTarget'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":");\n}","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If any future test calls","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"without arguments (defaulting to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), but the system under test","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"does","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"execute an initialization step that invokes","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"0","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"strictly means the manager shouldn't interact with the target at all.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said ignore tests for now. Just focus on non test files","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ignore tests for now. Just focus on non test files","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Because the actual source files (such as","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"or","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ReindexTargetStatsReporter.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") are not included in the snippet, I cannot analyze them for potential issues.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
-7314877865146810225
|
-3150928646201659260
|
idle
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse
In the newly added test
testEmptySelectionLogsAndReturnsFalse
, you explicitly mock the
BatchStatusManager
and set an expectation for
setUpdateTarget
:
PHP
Download code
Copy code
$batchStatusManager
->expects(
$this
->once())->method(
'setUpdateTarget'
)->with(
self
::UPDATE_TARGET);
However, later in the same test, you instantiate
UpdateProcessManager
manually and explicitly call:
PHP
Download code
Copy code
$processor
->setUpdateTarget(
self
::UPDATE_TARGET);
If
UpdateProcessManager::setUpdateTarget()
internally forwards that call to the underlying
BatchStatusManager
, your expectation passes. But if it does
not
forward it during that setter call (and instead calls it during
doUpdateEntitiesChunk
), the test might be passing for the wrong reason or could break if the internal implementation changes.
2. Inconsistent Environment Configuration in testEmptySelectionLogsAndReturnsFalse
2. Inconsistent Environment Configuration in
testEmptySelectionLogsAndReturnsFalse
In the new test, you instantiate the processor manually using
new UpdateProcessManager(...)
instead of using the updated
getProcessor()
helper method.
The Issue:
By bypassing
getProcessor()
, you lose the centralized setup. If the constructor requirements for
UpdateProcessManager
change in the future, this test will break and require manual updating, whereas tests using
getProcessor()
will be insulated from that change.
Recommendation:
Refactor
testEmptySelectionLogsAndReturnsFalse
to utilize a slightly modified or parameterized version of
getProcessor()
to keep the test suite DRY (Don't Repeat Yourself).
3. Tight Coupling to Log Strategies (withAnyArgs)
3. Tight Coupling to Log Strategies (
withAnyArgs
)
In
testRunUpdate
and
testRunDoUpdateButThrottled
, the precise log assertions from
prepareLogger()
were replaced with:
PHP
Download code
Copy code
Log::shouldReceive(
'info'
)->withAnyArgs();
Log::shouldReceive(
'debug'
)->withAnyArgs();
The Issue:
Using
withAnyArgs()
degrades the strictness of your test suite. If the code accidentally stops logging the specific, critical lifecycle messages (like
"[ EsUpdateProcessManager ] Finished updating entities in ES"
), these tests will still pass.
Recommendation:
Instead of completely silencing the logger with
withAnyArgs()
, use
with()
to assert that specific key tracking or lifecycle messages are still generated.
4. Risks with prepareStatusManager Default Value ($invokeTimes = 0)
4. Risks with
prepareStatusManager
Default Value (
$invokeTimes = 0
)
The helper method signature was changed to
private function prepareStatusManager(int $invokeTimes = 0): void
.
The Issue:
When
$invokeTimes
is
0
, it sets an explicit expectation that
setUpdateTarget
should
never
be called:
PHP
Download code
Copy code
else
{
$batchStatusManager
->expects(
$this
->never())->method(
'setUpdateTarget'
);
}
If any future test calls
prepareStatusManager()
without arguments (defaulting to
0
), but the system under test
does
execute an initialization step that invokes
setUpdateTarget
, the test will fail on an isolation constraint rather than actual logic failure. Ensure that a count of
0
strictly means the manager shouldn't interact with the target at all.
Good response
Bad response
Share & export
Copy
Show more options
You said ignore tests for now. Just focus on non test files
You said
ignore tests for now. Just focus on non test files
Copy prompt
Gemini said
Gemini said
I’d be happy to review the implementation code, but the git diff you provided only contains changes to a single test file:
UpdateProcessManagerTest.php
.
Because the actual source files (such as
UpdateProcessManager.php
or
ReindexTargetStatsReporter.php
) are not included in the snippet, I cannot analyze them for potential issues.
If you provide the code or the diff for the non-test files, I will gladly review them for logic flaws, architectural risks, or performance concerns.
Good response
Bad response
Share & export
Copy
Show more options...
|
85832
|
NULL
|
NULL
|
NULL
|
|
85834
|
2945
|
9
|
2026-05-28T13:19:20.554736+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974360554_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.14245346,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.24501197,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.27055067,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.28172386,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.47206703,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.49561054,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5067837,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.62649643,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.63766956,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.66081405,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Obsolete Helpers:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareLogger()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"silenceDatadogAndRedisLock()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"helper methods, replacing their inline functionality with standard","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Log::shouldReceive","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"expectations where needed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXCheckBox","text":"Good response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Bad response","depth":15,"on_screen":false,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Share & export","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy","depth":15,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show more options","depth":14,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"You said find potential issues","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"find potential issues","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Based on the provided git diff of","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", here are the potential issues, risks, and improvements identified in the changes:","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"1. Missing","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Expectation in","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
3990972314376044127
|
-8014842632041123708
|
visual_change
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked.
Removed Obsolete Helpers:
Deleted the
prepareLogger()
and
silenceDatadogAndRedisLock()
helper methods, replacing their inline functionality with standard
Log::shouldReceive
expectations where needed.
Good response
Bad response
Share & export
Copy
Show more options
You said find potential issues
You said
find potential issues
Copy prompt
Gemini said
Gemini said
Based on the provided git diff of
UpdateProcessManagerTest.php
, here are the potential issues, risks, and improvements identified in the changes:
1. Missing setUpdateTarget Expectation in testEmptySelectionLogsAndReturnsFalse
1. Missing
setUpdateTarget
Expectation in
testEmptySelectionLogsAndReturnsFalse...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85833
|
2945
|
8
|
2026-05-28T13:19:18.231943+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974358231_m2.jpg...
|
iTerm2
|
NULL
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
rircroxviewhsttonooountrnHelp© Pipelines - |Iminny rircroxviewhsttonooountrnHelp© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object errcJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 ded8 Jiminm,Platform Sorint 5.02 - Platform Te8 Jiminny7 (SRD-6881] (On demand) TransSona Strbramaal an at 27/05/2021O Illyana Netsova at 27/05/2026, 18Jimny+ New Tabroie.= github.com/fiWindow~ Google GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymoreeton Nencoenomicny(around 2014-2016) phpredis had some bugsno nx arguments were passeo, lnas tuly supportedic command for a very long time.redis driver, you simply pass an associative array ofe it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET coimmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino almicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pagejiminny / app 8<> Code17 Pull requests 33 (. Agents Actions Wiki Security and quality 12 Insights 3 SettingsJY-20963 fix deleted object import #12121 •13 Open LakyLak wants to merge 7 commits into master from JY-20963-fix-inport-on-deleted-entity@) Conversation 4• Commits 7 El Checks2© Files changed 3© All commits• Filter files.app/Http/Controllers/API/ActivityController.cho / *v F applee -370,6 +370, 10 @l public function sumnarize(Activity Sactivity): mixedscontacescrawevosvnccontacusooecd01"~ G Http/Controllers/API© ActivityController.php3713721v # Services/Crm/Salesforce# Service.php~ E tests/Unit/Services/Crm/Salesfor...# ServiceTest.php373374sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, scontact, Scraßervice, Sprospects);app/Services/Crm/Salesforce/Service.php Lee -1084,6 +1084,10 00 private function inportLead(ScraData): PLead18841e85Sthis-shandleObjectDeletion(Slead, Scrabata);rerurn sleaoh108909 -1146.8 +1158.14 A public function svncAccount(string Scrnid): ?Accountl11481147return Sthis-sinoortAccount(sstAccount114911581private function importAccount(Screbata): AccountOASOMОДTO0% L78• Thu 28 May 16:19:17Q Type to search• Checks pendingeode(Preview+483 -52 808810 0/3 viewedSubmit review+DUUUViewedsconacr= scraservce-ssynccontacsooec1f (1 Scontact instanceof Contact) &break;sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, Scontact, ScraService, Sprospects):478 .59 BaROnM Vinuedm .372373374• *375376 [PHONE]iii1890[PHONE]115e115111153 +1154Sthis-shandleObjectDeletion(Slead, Scrabata);if (Slead->trashedo) (return nullreturn Slead;return Sthis-sinoortAccount(SstAccount)private function importAccount(screbata): ?Account11 (t empty(Scrabata('IsDeleted'))) (...
|
NULL
|
-6606123271451341544
|
NULL
|
click
|
ocr
|
NULL
|
rircroxviewhsttonooountrnHelp© Pipelines - |Iminny rircroxviewhsttonooountrnHelp© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayDeleted object errcJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 ded8 Jiminm,Platform Sorint 5.02 - Platform Te8 Jiminny7 (SRD-6881] (On demand) TransSona Strbramaal an at 27/05/2021O Illyana Netsova at 27/05/2026, 18Jimny+ New Tabroie.= github.com/fiWindow~ Google GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymoreeton Nencoenomicny(around 2014-2016) phpredis had some bugsno nx arguments were passeo, lnas tuly supportedic command for a very long time.redis driver, you simply pass an associative array ofe it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET coimmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino almicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pagejiminny / app 8<> Code17 Pull requests 33 (. Agents Actions Wiki Security and quality 12 Insights 3 SettingsJY-20963 fix deleted object import #12121 •13 Open LakyLak wants to merge 7 commits into master from JY-20963-fix-inport-on-deleted-entity@) Conversation 4• Commits 7 El Checks2© Files changed 3© All commits• Filter files.app/Http/Controllers/API/ActivityController.cho / *v F applee -370,6 +370, 10 @l public function sumnarize(Activity Sactivity): mixedscontacescrawevosvnccontacusooecd01"~ G Http/Controllers/API© ActivityController.php3713721v # Services/Crm/Salesforce# Service.php~ E tests/Unit/Services/Crm/Salesfor...# ServiceTest.php373374sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, scontact, Scraßervice, Sprospects);app/Services/Crm/Salesforce/Service.php Lee -1084,6 +1084,10 00 private function inportLead(ScraData): PLead18841e85Sthis-shandleObjectDeletion(Slead, Scrabata);rerurn sleaoh108909 -1146.8 +1158.14 A public function svncAccount(string Scrnid): ?Accountl11481147return Sthis-sinoortAccount(sstAccount114911581private function importAccount(Screbata): AccountOASOMОДTO0% L78• Thu 28 May 16:19:17Q Type to search• Checks pendingeode(Preview+483 -52 808810 0/3 viewedSubmit review+DUUUViewedsconacr= scraservce-ssynccontacsooec1f (1 Scontact instanceof Contact) &break;sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, Scontact, ScraService, Sprospects):478 .59 BaROnM Vinuedm .372373374• *375376 [PHONE]iii1890[PHONE]115e115111153 +1154Sthis-shandleObjectDeletion(Slead, Scrabata);if (Slead->trashedo) (return nullreturn Slead;return Sthis-sinoortAccount(SstAccount)private function importAccount(screbata): ?Account11 (t empty(Scrabata('IsDeleted'))) (...
|
85831
|
NULL
|
NULL
|
NULL
|
|
85832
|
2944
|
7
|
2026-05-28T13:19:18.131651+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974358131_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Close tab
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle"}]...
|
2914094088296680485
|
-2241847995863866138
|
click
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Close tab
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85831
|
2945
|
7
|
2026-05-28T13:19:16.382618+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974356382_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked....
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.11402926,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.27055067,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"bounds":{"left":0.015957447,"top":0.28172386,"width":0.14245346,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"bounds":{"left":0.06732048,"top":0.27773345,"width":0.007978723,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"bounds":{"left":0.0,"top":0.30327216,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"bounds":{"left":0.013297873,"top":0.31444532,"width":0.030917553,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"bounds":{"left":0.0,"top":0.33599362,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"bounds":{"left":0.013297873,"top":0.3471668,"width":0.24301861,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"bounds":{"left":0.0,"top":0.36871508,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"bounds":{"left":0.013297873,"top":0.37988827,"width":0.09757314,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"bounds":{"left":0.0,"top":0.40143654,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.41260973,"width":0.08543883,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.43415803,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.44533122,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0,"top":0.4668795,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.47805268,"width":0.10106383,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"bounds":{"left":0.0028257978,"top":0.5047885,"width":0.036070477,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0028257978,"top":0.528332,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.015957447,"top":0.5395052,"width":0.013297873,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.0028257978,"top":0.56105345,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"bounds":{"left":0.015957447,"top":0.57222664,"width":0.1271609,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.5937749,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.6049481,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"bounds":{"left":0.0028257978,"top":0.62649643,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"bounds":{"left":0.015957447,"top":0.63766956,"width":0.12134308,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"bounds":{"left":0.0,"top":0.6592179,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"bounds":{"left":0.013297873,"top":0.6703911,"width":0.013131649,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"bounds":{"left":0.0028257978,"top":0.6935355,"width":0.07413564,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"bounds":{"left":0.0028257978,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"bounds":{"left":0.013796543,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"bounds":{"left":0.024933511,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"bounds":{"left":0.036070477,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"bounds":{"left":0.04720745,"top":0.97007185,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"bounds":{"left":0.28873006,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"bounds":{"left":0.30069813,"top":0.055067837,"width":0.010638298,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"bounds":{"left":0.08228058,"top":0.09736632,"width":0.015957447,"height":0.03830806},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"bounds":{"left":0.09823803,"top":0.10694334,"width":0.047539894,"height":0.01915403},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"bounds":{"left":0.1022274,"top":0.10853951,"width":0.017121011,"height":0.016360734},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"bounds":{"left":0.12084442,"top":0.10853951,"width":0.013796543,"height":0.015961692},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"bounds":{"left":0.28873006,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"bounds":{"left":0.30069813,"top":0.10215483,"width":0.011968086,"height":0.028731046},"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"bounds":{"left":0.079288565,"top":0.14445332,"width":0.0003324468,"height":0.0007980846},"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"bounds":{"left":0.079288565,"top":0.14684756,"width":0.1200133,"height":0.025538707},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"getProcessor()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to inject the new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"mock into the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManager","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and utilize the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Test Case Modifications","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Test Case Modifications","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed Memory Logging Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Deleted","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageEmitsGaugeWhenLockIsAbsent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testLogMemoryUsageSkipsGaugeWhenLockIsPresent","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"entirely, as the Redis lock and Datadog gauge logic were removed.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Empty Selection Test:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testEmptySelectionLogsAndReturnsFalse","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to verify that processing an empty selection logs a debug message, skips batch manager operations (","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"), skips the stats reporter, and cleanly returns","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"false","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated Existing Tests:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Modified","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunUpdate","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"testRunDoUpdateButThrottled","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to assert that the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter->report()","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method is called and to utilize the updated status manager mock.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Helper Method Refactoring","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Helper Method Refactoring","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Dynamic Status Manager Assertions:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Updated the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"prepareStatusManager(int $invokeTimes = 0)","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"method to accept an integer. This allows tests to dynamically assert exactly how many times methods like","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"generateName","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"setUpdateTarget","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":",","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"scheduleWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", and","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"finishWork","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"are invoked.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-3969668329696356318
|
-8014842632040058748
|
click
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:
Updated the
getProcessor()
method to inject the new
$statsReporter
mock into the
UpdateProcessManager
and utilize the
ENVIRONMENT
constant.
Test Case Modifications
Test Case Modifications
Removed Memory Logging Tests:
Deleted
testLogMemoryUsageEmitsGaugeWhenLockIsAbsent
and
testLogMemoryUsageSkipsGaugeWhenLockIsPresent
entirely, as the Redis lock and Datadog gauge logic were removed.
Added Empty Selection Test:
Introduced
testEmptySelectionLogsAndReturnsFalse
to verify that processing an empty selection logs a debug message, skips batch manager operations (
generateName
,
scheduleWork
,
finishWork
), skips the stats reporter, and cleanly returns
false
.
Updated Existing Tests:
Modified
testRunUpdate
and
testRunDoUpdateButThrottled
to assert that the
$statsReporter->report()
method is called and to utilize the updated status manager mock.
Helper Method Refactoring
Helper Method Refactoring
Dynamic Status Manager Assertions:
Updated the
prepareStatusManager(int $invokeTimes = 0)
method to accept an integer. This allows tests to dynamically assert exactly how many times methods like
generateName
,
setUpdateTarget
,
scheduleWork
, and
finishWork
are invoked....
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85830
|
2944
|
6
|
2026-05-28T13:19:16.279653+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974356279_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Login | Salesforce","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Login | Salesforce","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny\\Exceptions\\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Inbox (1,734) - lukas.kovalik@jiminny.com - Jiminny Mail","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20979] Resolve PHP 8.5.5 deprications - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"transcript ss issue","depth":4,"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Close Google Gemini (⌃X)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"on_screen":true,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"AI Chat settings","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Close","depth":3,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Main menu","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open mode picker, currently 3.1 Pro","depth":6,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Gemini","depth":13,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3.1 Pro","depth":11,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Chat","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open menu for conversation actions.","depth":5,"on_screen":true,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Conversation with Gemini","depth":7,"on_screen":true,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation with Gemini","depth":8,"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":13,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"You said","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\\Unit\\Component\\ES;5namespace Tests\\Unit\\Component\\ES;667-use ChaseConey\\LaravelDatadogHelper\\Datadog;8use Elastica\\Index;7use Elastica\\Index;9use Illuminate\\Support\\Facades\\App;8use Illuminate\\Support\\Facades\\App;10use Illuminate\\Support\\Facades\\Log;9use Illuminate\\Support\\Facades\\Log;@@ -20,6 +19,7 @@20use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;19use Jiminny\\Component\\ES\\Processor\\TargetEntitiesSelector;21use Jiminny\\Component\\ES\\Processor\\UpdateTarget;20use Jiminny\\Component\\ES\\Processor\\UpdateTarget;22use Jiminny\\Component\\ES\\QueuePriorityEnum;21use Jiminny\\Component\\ES\\QueuePriorityEnum;22+use Jiminny\\Component\\ES\\ReindexTargetStatsReporter;23use Jiminny\\Component\\ES\\UpdateProcessManager;23use Jiminny\\Component\\ES\\UpdateProcessManager;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;24use Jiminny\\Contracts\\ES\\UpdateTargetEnum;25use PHPUnit\\Framework\\Attributes\\CoversClass;25use PHPUnit\\Framework\\Attributes\\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \\Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.","depth":15,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Expand","depth":13,"on_screen":false,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Copy prompt","depth":12,"on_screen":false,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Gemini said","depth":12,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Gemini said","depth":13,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Here is a summary of the changes in the provided git diff for","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"UpdateProcessManagerTest.php","depth":17,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":":","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Structural and Dependency Changes","depth":15,"on_screen":false,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Structural and Dependency Changes","depth":16,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Replaced Datadog:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Removed the","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ChaseConey\\LaravelDatadogHelper\\Datadog","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"dependency and replaced it with","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jiminny\\Component\\ES\\ReindexTargetStatsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added Constants and Properties:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduced a new","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"ENVIRONMENT","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"constant (set to","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"'testing'","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":") and a","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"$statsReporter","depth":19,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"property to hold the mock for the new stats reporter.","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Processor Instantiation:","depth":18,"on_screen":false,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-8654108051834779297
|
-8005820039622414204
|
click
|
accessibility
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
Close tab
Login | Salesforce
Login | Salesforce
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Jiminny\Exceptions\EmailActivityImportException: [Email Import] Failed for InboxEmail ID: 125695762: Error: Request failed — jiminny — app
Inbox (1,734) - [EMAIL] - Jiminny Mail
Inbox (1,734) - [EMAIL] - Jiminny Mail
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
[JY-20979] Resolve PHP 8.5.5 deprications - Jira
Jiminny
Jiminny
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
transcript ss issue
Jiminny
Jiminny
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Sona Subramanian at 27/05/2026, 17:46:08 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Iliyana Netseva at 27/05/2026, 18:48:18 - Session Replay - LogRocket
Jiminny
Jiminny
New Tab
Customize sidebar
Close Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
AI Chat settings
Close
Main menu
Open mode picker, currently 3.1 Pro
Gemini
3.1 Pro
New Chat
Open menu for conversation actions.
Conversation with Gemini
Conversation with Gemini
You said I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected. Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
You said
I’m on page “<tabTitle>Jy 20910 schedule parallel update target processin</tabTitle>” with “<selection>@@ -4,7 +4,6 @@445namespace Tests\Unit\Component\ES;5namespace Tests\Unit\Component\ES;667-use ChaseConey\LaravelDatadogHelper\Datadog;8use Elastica\Index;7use Elastica\Index;9use Illuminate\Support\Facades\App;8use Illuminate\Support\Facades\App;10use Illuminate\Support\Facades\Log;9use Illuminate\Support\Facades\Log;@@ -20,6 +19,7 @@20use Jiminny\Component\ES\Processor\TargetEntitiesSelector;19use Jiminny\Component\ES\Processor\TargetEntitiesSelector;21use Jiminny\Component\ES\Processor\UpdateTarget;20use Jiminny\Component\ES\Processor\UpdateTarget;22use Jiminny\Component\ES\QueuePriorityEnum;21use Jiminny\Component\ES\QueuePriorityEnum;22+use Jiminny\Component\ES\ReindexTargetStatsReporter;23use Jiminny\Component\ES\UpdateProcessManager;23use Jiminny\Component\ES\UpdateProcessManager;24use Jiminny\Contracts\ES\UpdateTargetEnum;24use Jiminny\Contracts\ES\UpdateTargetEnum;25use PHPUnit\Framework\Attributes\CoversClass;25use PHPUnit\Framework\Attributes\CoversClass;@@ -31,6 +31,7 @@ class UpdateProcessManagerTest extends TestCase31{31{32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';32private const string BATCH_NAME = '9440de7a-1c0f-4541-a235-592f2117bb20';33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;33private const string UPDATE_TARGET = UpdateTarget::ACTIVITY;34+private const string ENVIRONMENT = 'testing';343535private array $normalPriority = [];36private array $normalPriority = [];36private array $highPriority = [];37private array $highPriority = [];@@ -40,6 +41,7 @@ class UpdateProcessManagerTest extends TestCase40private ?SimpleCollection $documentsToUpdate = null;41private ?SimpleCollection $documentsToUpdate = null;414242private BatchStatusManager|MockObject|null $batchStatusManager = null;43private BatchStatusManager|MockObject|null $batchStatusManager = null;44+private ReindexTargetStatsReporter|MockObject|null $statsReporter = null;43private Index|MockObject|null $targetIndex = null;45private Index|MockObject|null $targetIndex = null;444645private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;47private string|UpdateTargetEnum $updateTargetEntity = UpdateTarget::ACTIVITY;@@ -68,8 +70,13 @@ protected function setUp(): void68array_diff($allEntities, $deleteIds)70array_diff($allEntities, $deleteIds)69 );71 );707271-$this->prepareStatusManager();73+$this->statsReporter = $this->createMock(ReindexTargetStatsReporter::class);72-$this->prepareLogger();74+$this->statsReporter->expects($this->once())75+ ->method('setEnvironment')76+ ->with(self::ENVIRONMENT);77+$this->statsReporter->expects($this->once())78+ ->method('setUpdateTarget')79+ ->with(self::UPDATE_TARGET);73 }80 }748175/**82/**@@ -81,76 +88,75 @@ public function testRunUpdate(): void81// Also test that the trait works with entities and strings alike88// Also test that the trait works with entities and strings alike82$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;89$this->updateTargetEntity = UpdateTargetEnum::ACTIVITY;839084-$this->silenceDatadogAndRedisLock();91+ Log::shouldReceive('info')->withAnyArgs();92+ Log::shouldReceive('debug')->withAnyArgs();93+94+$this->statsReporter->expects($this->once())->method('report');95+96+$this->prepareStatusManager(1);859786$processor = $this->getProcessor();98$processor = $this->getProcessor();879988// There are exactly 250 chunks100// There are exactly 250 chunks89$this->assertTrue($processor->doUpdateEntitiesChunk());101$this->assertTrue($processor->doUpdateEntitiesChunk());102+90// But the second execution is on empty set103// But the second execution is on empty set91$this->assertFalse($processor->doUpdateEntitiesChunk());104$this->assertFalse($processor->doUpdateEntitiesChunk());92 }105 }9310694-/**107+public function testEmptySelectionLogsAndReturnsFalse(): void95- * When no Redis lock exists, logMemoryUsage should set the lock and emit a Datadog gauge96- * with the correct stat name, sample rate, and environment/type tags.97- */98-public function testLogMemoryUsageEmitsGaugeWhenLockIsAbsent(): void99 {108 {100-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);109+$batchStatusManager = $this->createMock(BatchStatusManager::class);101-110+$batchStatusManager->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);102- Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(null);111+$batchStatusManager->expects($this->never())->method('generateName');103- Redis::shouldReceive('set')->once()->with($gaugeLockKey, true);112+$batchStatusManager->expects($this->never())->method('scheduleWork');104- Redis::shouldReceive('expire')->once()->with($gaugeLockKey, 60);113+$batchStatusManager->expects($this->never())->method('finishWork');105-106- Datadog::shouldReceive('increment')->once()->withAnyArgs();107- Datadog::shouldReceive('gauge')108- ->once()109- ->with(110-'jiminny.reindex-memory-usage',111- \Mockery::type('int'),112-1,113- ['environment' => 'staging', 'type' => self::UPDATE_TARGET]114- );115-116-$processor = $this->getProcessor();117-$processor->setEnvironment('staging');118114119-$processor->doUpdateEntitiesChunk();115+$emptySelection = $this->createMock(SelectionList::class);120-}116+ $emptySelection->expects($this->once())->method('isEmpty')->willReturn(true);121117122-/**118+$entitySelector = $this->createMock(TargetEntitiesSelector::class);123- * When a Redis lock already exists, logMemoryUsage should return early119+$entitySelector->expects($this->once())->method('setUpdateTarget')->with(self::UPDATE_TARGET);124- * and not emit a Datadog gauge.120+$entitySelector->expects($this->once())->method('setBatchStatusManager')->with($batchStatusManager);125- */121+$entitySelector->expects($this->once())->method('select')->willReturn($emptySelection);126-public function testLogMemoryUsageSkipsGaugeWhenLockIsPresent(): void127- {128-$gaugeLockKey = sprintf('%s-process-manager-lock', self::UPDATE_TARGET);129122130-Redis::shouldReceive('get')->once()->with($gaugeLockKey)->andReturn(true);123+Log::shouldReceive('debug')131-Redis::shouldReceive('set')->never();124+ ->once()132-Redis::shouldReceive('expire')->never();125+ ->with('[ EsUpdateProcessManager ] Empty selection', ['update_target' => self::UPDATE_TARGET]);133126134- Datadog::shouldReceive('increment')->once()->withAnyArgs();127+$this->statsReporter->expects($this->never())->method('report');135- Datadog::shouldReceive('gauge')->never();136128137-$processor = $this->getProcessor();129+$processor = new UpdateProcessManager(138-$processor->setEnvironment('staging');130+ esClient: $this->getEsClientMock(),131+ entitySelector: $entitySelector,132+ batchStatusManager: $batchStatusManager,133+ deleteDocumentsAction: $this->createMock(DeleteDocumentsAction::class),134+ upsertDocumentsAction: $this->createMock(UpsertDocumentsAction::class),135+ loadDocumentsAction: $this->createMock(LoadDocumentsAction::class),136+ statsReporter: $this->statsReporter,137+ );138+$processor->setEnvironment(self::ENVIRONMENT);139+$processor->setUpdateTarget(self::UPDATE_TARGET);140+$processor->bootstrap();139141140-$processor->doUpdateEntitiesChunk();142+$this->assertFalse($processor->doUpdateEntitiesChunk());141 }143 }142144143public function testRunDoUpdateButThrottled(): void145public function testRunDoUpdateButThrottled(): void144 {146 {145$this->isThrottled = true;147$this->isThrottled = true;146148147-$this->silenceDatadogAndRedisLock();149+ Log::shouldReceive('info')->withAnyArgs();150+151+$this->statsReporter->expects($this->once())->method('report');148152149// Reschedule High priority153// Reschedule High priority150 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);154 Redis::shouldReceive('saddarray')->with('activities-for-update-priority', $this->highPriority);151// Reschedule low priority155// Reschedule low priority152 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);156 Redis::shouldReceive('saddarray')->with('activities-for-update', $this->normalPriority);153157158+$this->prepareStatusManager(1);159+154$processor = $this->getProcessor();160$processor = $this->getProcessor();155161156$this->assertTrue($processor->doUpdateEntitiesChunk());162$this->assertTrue($processor->doUpdateEntitiesChunk());@@ -165,10 +171,11 @@ private function getProcessor(): UpdateProcessManager165 deleteDocumentsAction: $this->getDeleteActionMock(),171 deleteDocumentsAction: $this->getDeleteActionMock(),166 upsertDocumentsAction: $this->getUpsertActionMock(),172 upsertDocumentsAction: $this->getUpsertActionMock(),167 loadDocumentsAction: $this->getLoadDocumentsMock(),173 loadDocumentsAction: $this->getLoadDocumentsMock(),174+ statsReporter: $this->statsReporter,168 );175 );169176170$updateProcessor->setUpdateTarget($this->updateTargetEntity);177$updateProcessor->setUpdateTarget($this->updateTargetEntity);171-$updateProcessor->setEnvironment('test-env');178+$updateProcessor->setEnvironment(self::ENVIRONMENT);172179173$updateProcessor->bootstrap();180$updateProcessor->bootstrap();174181@@ -195,23 +202,6 @@ private function getEsClientMock(): Client|MockObject195return $clientMock;202return $clientMock;196 }203 }197204198-private function prepareLogger(): void199- {200- Log::shouldReceive('info')201- ->atLeast()202- ->once()203- ->with('[ EsUpdateProcessManager ] Finished updating entities in ES', $this->anything());204- }205-206-private function silenceDatadogAndRedisLock(): void207- {208- Datadog::shouldReceive('increment')->atLeast()->once()->withAnyArgs();209- Datadog::shouldReceive('gauge')->withAnyArgs();210- Redis::shouldReceive('get')->withAnyArgs()->andReturn(null);211- Redis::shouldReceive('set')->withAnyArgs();212- Redis::shouldReceive('expire')->withAnyArgs();213- }214-215private function getDeleteActionMock(): DeleteDocumentsAction|MockObject205private function getDeleteActionMock(): DeleteDocumentsAction|MockObject216 {206 {217$deleteAction = $this->createMock(DeleteDocumentsAction::class);207$deleteAction = $this->createMock(DeleteDocumentsAction::class);@@ -320,26 +310,30 @@ private function mockSelection(): SelectionList|MockObject320return $selectionList;310return $selectionList;321 }311 }322312323-private function prepareStatusManager(): void313+private function prepareStatusManager(int $invokeTimes = 0): void324 {314 {325$batchStatusManager = $this->createMock(BatchStatusManager::class);315$batchStatusManager = $this->createMock(BatchStatusManager::class);326316327-$batchStatusManager->expects($this->atLeastOnce())317+if ($invokeTimes) {318+$batchStatusManager->expects($this->once())319+ ->method('setUpdateTarget')320+ ->with(self::UPDATE_TARGET);321+ } else {322+$batchStatusManager->expects($this->never())->method('setUpdateTarget');323+ }324+325+$batchStatusManager->expects($this->exactly($invokeTimes))328 ->method('generateName')326 ->method('generateName')329 ->willReturn(self::BATCH_NAME);327 ->willReturn(self::BATCH_NAME);330328331-$batchStatusManager->expects($this->atLeastOnce())329+$batchStatusManager->expects($this->exactly($invokeTimes))332- ->method('setUpdateTarget')333- ->with(self::UPDATE_TARGET);334-335-$batchStatusManager->expects($this->atLeastOnce())336 ->method('scheduleWork')330 ->method('scheduleWork')337 ->with(331 ->with(338array_merge($this->highPriority, $this->normalPriority),332array_merge($this->highPriority, $this->normalPriority),339self::BATCH_NAME333self::BATCH_NAME340 );334 );341335342-$batchStatusManager->expects($this->atLeastOnce())336+$batchStatusManager->expects($this->exactly($invokeTimes))343 ->method('finishWork')337 ->method('finishWork')344 ->with(self::BATCH_NAME);338 ->with(self::BATCH_NAME);345339</selection>” selected.
Please summarize the selection using precise and concise language. Use headers and bulleted lists in the summary, to make it scannable. Maintain the meaning and factual accuracy.
Expand
Copy prompt
Gemini said
Gemini said
Here is a summary of the changes in the provided git diff for
UpdateProcessManagerTest.php
:
Structural and Dependency Changes
Structural and Dependency Changes
Replaced Datadog:
Removed the
ChaseConey\LaravelDatadogHelper\Datadog
dependency and replaced it with
Jiminny\Component\ES\ReindexTargetStatsReporter
.
Added Constants and Properties:
Introduced a new
ENVIRONMENT
constant (set to
'testing'
) and a
$statsReporter
property to hold the mock for the new stats reporter.
Processor Instantiation:...
|
85827
|
NULL
|
NULL
|
NULL
|
|
85829
|
2945
|
6
|
2026-05-28T13:19:13.462460+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974353462_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Deleted object error","depth":4,"bounds":{"left":0.0028257978,"top":0.21428572,"width":0.039228722,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXRadioButton","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":4,"bounds":{"left":0.0028257978,"top":0.23782921,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Uncovered Lines on New Code - app in Jiminny SonarQube Cloud","depth":5,"bounds":{"left":0.015957447,"top":0.2490024,"width":0.11402926,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app","depth":4,"bounds":{"left":0.0028257978,"top":0.27055067,"width":0.07679521,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true}]...
|
4005828102058786328
|
-7727228562094562093
|
visual_change
|
hybrid
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
Deleted object error
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
Uncovered Lines on New Code - app in Jiminny SonarQube Cloud
JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app
rircroxviewhsttonooountrn© Pipelines - |Iminnylapp* (JY-20613) Allow owner's role to tText relayxUewredtines on New codJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 dedPlatform Sorint 5.02 - Platform Te8 Jiminny7 (SRD-6881] (On demand) TransSona Strbramaal an at 27/05/2021O Illyana Netsova at 27/05/2026, 18Jimny+ New Tabroie.WindowHelp= github.com/finydpo ouleicu chonde~ Google GeminiGemini 3.1 Pro ~That is a very common misconception, but it is not true anymore!While it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTLESECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavina amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pagejiminny / app C<> Code17 Puli requests 33 (. Agents Actions Wiki Security and quality 12 ~ Insights 3 SettingsJY-20963 fix deleted object import #12121 •11 Open LakyLak wants to merge 7 commits into naster from JY-28963-fix-inport-on-deleted-entityP) Conversation 4a Commits 7 El Checks 2© Files changed 3OAll commits -• Filter files.app/Http/Controllers/API/ActivityController.cho /v F applee -370,6 +370, 10 @l public function sumnarize(Activity Sactivity): mixedscontacsscrawer-osvnccontactsoo.ecdo~ G Http/Controllers/API© ActivityController.phpv # Services/Crm/SalesforceService.p.tests/Unit/Services/Crm/Salesfor~ E tests/Unit/Services/Crm/Salesfor...21 ServiceTest.oho374sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, Scontact, ScraService, Sprospects);app/Services/Crm/Salesforce/Service.php L18841e85108911481147114911581ee -1884,6 +1084,10 00 private function inportLead(Scrabata): PLeadsunns-phanoleoo ecuelee.ons caorXttuarahrerurn seaohonuord +iabu.e n oubute tunccion sune ccountistrind Scriid: Zaccountreturn Sthis-sinoortAccount(SstAccount)private function importAccount(ScraData): Accoun:OASOMОД8• Thu 28 May 16:19:13Q Type to search8 -• Checks pendingeode(Preview4403 -52 8088O Refresh O0/3 viewedSubmit review+DUUUViewedScontact = ScrnService->syncContact(SobjectId):1f (1 Scontact instanceof Contact) &break;sthis->logger->info('resolving account");Saccount = Sthis->resolveAccount(Stean, Scontact, ScraService, Sprospects):478 .59 BaRon M Vinuedm .372375376 [PHONE]188618891890[PHONE]115e11511153 +1154Sthis-shandleObjectDeletion(Slead, Scrabata);if (Slead->trashedo) (return null.return Slead;return Sthis->inoortAccount (SstAccount)private function importAccount(screbata): ?Account11 (l enpty(Scrabata('IsDeleted'))) (...
|
85828
|
NULL
|
NULL
|
NULL
|
|
85828
|
2945
|
5
|
2026-05-28T13:19:10.181918+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974350181_m2.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira","depth":4,"bounds":{"left":0.0018284575,"top":0.0518755,"width":0.038065158,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"[SRD-6881] [On demand] Transcription in saved search disappears - Jira","depth":4,"bounds":{"left":0.039893616,"top":0.0518755,"width":0.037898935,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"bounds":{"left":0.0,"top":0.09497207,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pipelines - jiminny/app","depth":5,"bounds":{"left":0.013297873,"top":0.10614525,"width":0.039228722,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"BE upgrade libraries","depth":4,"bounds":{"left":0.0028257978,"top":0.13288109,"width":0.03939495,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":4,"bounds":{"left":0.0,"top":0.15203512,"width":0.07962101,"height":0.032721467},"on_screen":true,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"[JY-20613] Allow owner's role to be selected when setting up a trial - Jira","depth":5,"bounds":{"left":0.013297873,"top":0.1632083,"width":0.12799202,"height":0.010774142},"on_screen":true,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Text relay","depth":4,"bounds":{"left":0.0028257978,"top":0.18994413,"width":0.020279255,"height":0.01915403},"on_screen":true,"role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3403705732781473960
|
-2178800898474990384
|
click
|
hybrid
|
NULL
|
Platform Sprint 5 Q2 - Platform Team - Scrum Board Platform Sprint 5 Q2 - Platform Team - Scrum Board - Jira
[SRD-6881] [On demand] Transcription in saved search disappears - Jira
Pipelines - jiminny/app
Pipelines - jiminny/app
BE upgrade libraries
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
[JY-20613] Allow owner's role to be selected when setting up a trial - Jira
Text relay
rircroxViewhsttonooountrnroie.WindowHelp= github.com/finydpo ouleicu chonde~ Google GeminiGemini 3.1 Pro ~Pipelines - jiminny/app* (JY-20613) Allow owner's role to tText relayxUewredtines on New codJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 ded8 Jiminm,Platform Sorint 5.02 - Platform Te8 Jiminny* (SRD-6881) (0n demand) TransoSona Subramaaian at 27/05/202O Illyana Netsova at 27/05/2026, 18Jimny+ New TabThat is a very common misconception, but it is not true anymoreWhile it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTL-SECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pageE Tr OpenJY-20963 1ix deleted obiect imoort #21211All commits - LakyLak wants to merge 7 commits into master from JY-20963-fix-import-on-deleted-entity (Q Filter files..~ Бi app~ $ Http/Controllers/APIE ActivityController.php~ E Services/Crm/Salesforce# Service.php* E tests/Unit/Services/Crm/Salesfor….® ServiceTest.phpv app/Services/Crm/Salesforce/Service-php C *80 -1511,57 +1525,21 @ public function syncContact(string Scrmid): ?Contac:151115131514-1515recurn ounzs-piasortcontactlastcontaccprivate function importContact(ScraData): ContactSaccount = null// Contacts may not have accounts...wissetScr-Datal"Account.csaccount = Sthis->config→>accounts()-swhere('cm orovider id". (string) Scrbatal"Accountid"eTarstUhif (Saccount === null) ‹saccountthis-ssyne-ccountiscmtatal'xccounttdЕЕЕЕЕЕАААВВВВВВВВВВВВВВВВКВВВВВВЕВScountrycode = Screbatal"Mari inecountrvcode'? nutiSalestorce aulous custon "countrtes" to be crested, Dfsreaard these.if (scountryCode && Sthis->countriesMap->countryExists(ScountryCode) .== false) (Scountrycode = nulll/1 If we have no country code, try to parse it from the country namelif (ScountryCode uaa null 6& Saccount) €Scountrycode = saccount-scountry code.Sext = nuli:EnarcerMucher=fl+1Cenoty Scrrbata."Phone" =a= talse)touekor e Cres.ltai+teereharat.ohaa?26 8814SparsedNumber = parsePhoneNumber (ScountryCode, Snumber):1f (empty(SparsedNunber('ext')) ae= false) ‹Cayt = Str.-linit(6narce/Mcherf.ext*1.10. 1a)1553GSMOAX0 8• Thu 28 May 16:19:09Refresh 0/ 3 viewedChecks pendingSubmitrevie B°+78 -52 BBB00 M Viewed1 .152515271528 +1530 :1531return sthis-aleportContact/stContact);prtuate frucetion deportcontsct(serebrto): Kontast4* ( enoty(ScreData("IsDeleted'])) ‹|Sthis-shandleEntity0eletionByProviderId(Sthis->config->contacts(), Screbata);...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85827
|
2944
|
5
|
2026-05-28T13:19:07.519868+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974347519_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹$0(ah]-zshDOCKER881DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%X5ec2-user@ip-10-30-129-...100% <78 • Thu 28 May 16:19:07181ec2-user@ip-10-30-140-...₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
NULL
|
949000736302957567
|
NULL
|
visual_change
|
ocr
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹$0(ah]-zshDOCKER881DEV (docker)₴82-zshscreenpipe"O ₴4-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phplukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddocker exec -it docker_lamp_1 bash -c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ ;xddocker exec -itdocker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv: cannot stat '/usr/local/etc/php/conf.d/xdebug.ini': No such file or directoryWhat's next:Try Docker Debug for seamless, persistent debugging tools in any container or image + docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $ csfixdocker exec -it docker_lamp_1•/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --using-cache=no --diffPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.PHP runtime: 8.5.5Loaded config default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%X5ec2-user@ip-10-30-129-...100% <78 • Thu 28 May 16:19:07181ec2-user@ip-10-30-140-...₴7Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they will stop working in next major release):- Rule set"@PHP74Migration" is deprecated. Use "@PHP7x4Migration" instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Ruleset "@PHP83Migration" is deprecated. Use "@PHP8x3Migration" instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $I...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85826
|
2945
|
4
|
2026-05-28T13:19:06.794074+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974346794_m2.jpg...
|
iTerm2
|
NULL
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
rircroxViewhsttonooountrnroie.WindowHelp= github.c rircroxViewhsttonooountrnroie.WindowHelp= github.com/finydpo ouleicu chonde~ Google GeminiGemini 3.1 Pro ~Pipelines - jiminny/app* (JY-20613) Allow owner's role to tText relayxUewredtines on New codJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 ded8 Jiminm,Platform Sorint 5.02 - Platform Te8 Jiminny7 (SRD-6881] (On demand) TransSona Subramaaian at 27/05/202O Illyana Netsova at 27/05/2026, 18Jimny+ New TabThat is a very common misconception, but it is not true anymoreWhile it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTL-SECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pageE Tr OpenJY-20963 1ix deleted obiect imoort #21211All commits - LakyLak wants to merge 7 commits into master from JY-20963-fix-import-on-deleted-entity (Q Filter files..~ Бi app~ $ Http/Controllers/APIE ActivityController.php~ E Services/Crm/Salesforce# Service.php* E tests/Unit/Services/Crm/Salesfor….® ServiceTest.phpv app/Services/Crm/Salesforce/Service-php C *80 -1511,57 +1525,21 @ public function syncContact(string Scrmid): ?Contac:151115131514-1515recurn ounzs-piasortcontactlastcontaccprivate function importContact(ScraData): Contactsaccount = null// Contacts may not have accounts...wissetScr-Datal"Account.csaccount = Sthis->config->accounts()-swhere('cm orovider id". (string) Scrbatal"Accountid"eTarstUhif (Saccount === null) ‹saccountthis-ssyne-ccountiscmtatal'xccounttdЕЕЕЕЕЕАААВВВВВВВВВВВВВВВВКВВВВВВЕВScountrycode = Screbatal"Mari inecountrvcode'? nutiSalestorce aulous custon "countrtes" to be crested, Dfsreaard these.if (scountryCode && Sthis->countriesMap->countryExists(ScountryCode) .== false) (Scountrycode = nulll/1 If we have no country code, try to parse it from the country namelif (ScountryCode uaa null 6& Saccount) €Scountrycode = saccount-scountry code.Sext = nuli:EnarcerMucher = fl.1Cenoty Scrrbata."Phone" =a= talse)touekor e Cres.ltai+teereharat.ohaa?26 8814SparsedNumber = parsePhoneNumber (ScountryCode, Snumber):1f (empty(SparsedNunber('ext')) ae= false) ‹Cayt = Str.-linit(6narce/Mcherf.ext*1.10. 1a)1553GSMOAX0 8• Thu 28 May 16:19:06Refresh 0/ 3 viewedChecks pendingSubmitrevie B°+78 -52 BBB00 M Viewed1 .152515271528 +1530 :1531return sthis-aleportContact/stContact);prtuate frucetion deportcontsct(serebrto): Kontast4* ( enoty(ScreData("IsDeleted'])) ‹|Sthis-shandleEntity0eletionByProviderId(Sthis->config->contacts(), Screbata);...
|
NULL
|
-2937786561449263843
|
NULL
|
visual_change
|
ocr
|
NULL
|
rircroxViewhsttonooountrnroie.WindowHelp= github.c rircroxViewhsttonooountrnroie.WindowHelp= github.com/finydpo ouleicu chonde~ Google GeminiGemini 3.1 Pro ~Pipelines - jiminny/app* (JY-20613) Allow owner's role to tText relayxUewredtines on New codJY-20963 fix deleted objecti XJiminny\Exceptions(EmailActivityfrM'inbox (1734) - Aukas.kovallk@jlmirioonre Reso ve php 81.15 ded8 Jiminm,Platform Sorint 5.02 - Platform Te8 Jiminny7 (SRD-6881] (On demand) TransSona Subramaaian at 27/05/202O Illyana Netsova at 27/05/2026, 18Jimny+ New TabThat is a very common misconception, but it is not true anymoreWhile it is true that many years ago (around 2014-2016) (phpredis had some bugsregardling tne order in wnich ex and nx arguments were passeo, lnas tuly supportedcombining them into a single atomic command for a very long time.To do this atomically using the phpredis driver, you simply pass an associative array ofoptions as the third argument.Here is exactly how you would write it in your code:PHPSlockKey = sprintf(self::LOCK_KEY, $this->updateTarget);// This executes a single, atomic SET conmmand with both NX and EXSacquired = Redis::set(lockkey, true, L'NX, "EX => SeLT::LOCK-TTL-SECONDSJ)Eif (! Sacquired) &// Another process already holds the lockreturn;I... report your metrics ...By relvina on senarate det, setand expire commands, vou are leavino amicrosecond gap open. In your new multi-process Supervisor architecture, two parallelworkers can check the get, both see (null), and both proceed to write the lock andpush duplicate metrics. Using the array syntax above closes that gap completely.A Cleaner Laravel AlternativeSince you are inside a Laravel app, you don't even need to fight with driver-specific Redissyntax. Laravel provides a dedicated, atomic lock manager that handles the phpredis/Ask cemintSummarize pageE Tr OpenJY-20963 1ix deleted obiect imoort #21211All commits - LakyLak wants to merge 7 commits into master from JY-20963-fix-import-on-deleted-entity (Q Filter files..~ Бi app~ $ Http/Controllers/APIE ActivityController.php~ E Services/Crm/Salesforce# Service.php* E tests/Unit/Services/Crm/Salesfor….® ServiceTest.phpv app/Services/Crm/Salesforce/Service-php C *80 -1511,57 +1525,21 @ public function syncContact(string Scrmid): ?Contac:151115131514-1515recurn ounzs-piasortcontactlastcontaccprivate function importContact(ScraData): Contactsaccount = null// Contacts may not have accounts...wissetScr-Datal"Account.csaccount = Sthis->config->accounts()-swhere('cm orovider id". (string) Scrbatal"Accountid"eTarstUhif (Saccount === null) ‹saccountthis-ssyne-ccountiscmtatal'xccounttdЕЕЕЕЕЕАААВВВВВВВВВВВВВВВВКВВВВВВЕВScountrycode = Screbatal"Mari inecountrvcode'? nutiSalestorce aulous custon "countrtes" to be crested, Dfsreaard these.if (scountryCode && Sthis->countriesMap->countryExists(ScountryCode) .== false) (Scountrycode = nulll/1 If we have no country code, try to parse it from the country namelif (ScountryCode uaa null 6& Saccount) €Scountrycode = saccount-scountry code.Sext = nuli:EnarcerMucher = fl.1Cenoty Scrrbata."Phone" =a= talse)touekor e Cres.ltai+teereharat.ohaa?26 8814SparsedNumber = parsePhoneNumber (ScountryCode, Snumber):1f (empty(SparsedNunber('ext')) ae= false) ‹Cayt = Str.-linit(6narce/Mcherf.ext*1.10. 1a)1553GSMOAX0 8• Thu 28 May 16:19:06Refresh 0/ 3 viewedChecks pendingSubmitrevie B°+78 -52 BBB00 M Viewed1 .152515271528 +1530 :1531return sthis-aleportContact/stContact);prtuate frucetion deportcontsct(serebrto): Kontast4* ( enoty(ScreData("IsDeleted'])) ‹|Sthis-shandleEntity0eletionByProviderId(Sthis->config->contacts(), Screbata);...
|
85822
|
NULL
|
NULL
|
NULL
|
|
85825
|
2944
|
4
|
2026-05-28T13:19:04.274735+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974344274_m1.jpg...
|
Firefox
|
JY-20963 fix deleted object import by LakyLak · Pu JY-20963 fix deleted object import by LakyLak · Pull Request #12121 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/12121/changes
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹ >0 lol-zshDOCKER881DEV (docker)₴82-zshN3screenpipe"884-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phpukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddockerexec -it docker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] $ ;xddockerexeс-itdocker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv•lluen/lneallnbalahnleandc:1a ^nW85ec2-user@ip-10-30-129-...100% C8• Thu 28 May 16:19:03181ec2-user@ip-10-30-140-…₴7PS$I31Ph.FirefoxPHPruntime:8.5.5Loadedconfig default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they willstop working in next major release):Rule set"@PHP74Migration"is deprecated. Use"@PHP7x4Migration" instead.Rule set "@PHP80Migration"is deprecated.Ruleset"@PHP81Migration"Use "@PHP8x0Migration" instead.is deprecated.Use"@PHP8x1Migration" instead.Rule set "@PHP82Migration"is deprecated. Use"@PHP8x?Migration" instead.Ruleset"@PHP83Migration"is deprecated. Use"@PHP8x3Migration" instead.Ruleset"@PHP84Migration"is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $0...
|
NULL
|
6351632482296581053
|
NULL
|
visual_change
|
ocr
|
NULL
|
iTerm2ShellEditViewSessionScriptsProfilesWindowHel iTerm2ShellEditViewSessionScriptsProfilesWindowHelp‹ >0 lol-zshDOCKER881DEV (docker)₴82-zshN3screenpipe"884-zshcreate mode 100644 tests/Unit/Component/TranscriptionSummary/Services/TranscriptionSummaryIndexingServiceTest.phpukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (master) $ ;xddockerexec -it docker_lamp_1 bash-c "mv /usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"What's next:Try Docker Debug forseamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at [URL_WITH_CREDENTIALS] $ ;xddockerexeс-itdocker_lamp_1 bash -c"mv/usr/local/etc/php/conf.d/xdebug.ini ~/xdebug.ini"mv•lluen/lneallnbalahnleandc:1a ^nW85ec2-user@ip-10-30-129-...100% C8• Thu 28 May 16:19:03181ec2-user@ip-10-30-140-…₴7PS$I31Ph.FirefoxPHPruntime:8.5.5Loadedconfig default from ".php-cs-fixer.dist.php".Running analysis on 7 cores with 10 files per process.5697/5697 C8I 100%Fixed 0 of 5697 files in 67.976 seconds, 799.06 MBmemory usedDetected deprecations in use (they willstop working in next major release):Rule set"@PHP74Migration"is deprecated. Use"@PHP7x4Migration" instead.Rule set "@PHP80Migration"is deprecated.Ruleset"@PHP81Migration"Use "@PHP8x0Migration" instead.is deprecated.Use"@PHP8x1Migration" instead.Rule set "@PHP82Migration"is deprecated. Use"@PHP8x?Migration" instead.Ruleset"@PHP83Migration"is deprecated. Use"@PHP8x3Migration" instead.Ruleset"@PHP84Migration"is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug docker_lamp_1Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20963-fix-import-on-deleted-entity) $0...
|
85821
|
NULL
|
NULL
|
NULL
|
|
85824
|
2945
|
3
|
2026-05-28T13:18:47.451634+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974327451_m2.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"bounds":{"left":0.8753325,"top":0.915403,"width":0.11037234,"height":0.027134877},"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.8753325,"top":0.915403,"width":0.09740692,"height":0.027134877},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"bounds":{"left":0.8753325,"top":0.9481245,"width":0.03523936,"height":0.013567438},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11569149,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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.85638297,"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":"ServiceTest","depth":6,"bounds":{"left":0.87167555,"top":0.019952115,"width":0.043882977,"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 'ServiceTest'","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 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.010305851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.009640957,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"bounds":{"left":0.41589096,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"bounds":{"left":0.4245346,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"bounds":{"left":0.43550533,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"bounds":{"left":0.44414893,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"bounds":{"left":0.45279256,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"bounds":{"left":0.4637633,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"bounds":{"left":0.47473404,"top":0.09896249,"width":0.024268618,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"bounds":{"left":0.5013298,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"bounds":{"left":0.51230055,"top":0.09896249,"width":0.029587766,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"bounds":{"left":0.7237367,"top":0.09896249,"width":0.02825798,"height":0.01915403},"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":"45","depth":4,"bounds":{"left":0.6938165,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.70611703,"top":0.123703115,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"bounds":{"left":0.71542555,"top":0.123703115,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","depth":4,"bounds":{"left":0.72706115,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.12210695,"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.7463431,"top":0.12210695,"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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
85822
|
NULL
|
NULL
|
NULL
|
|
85823
|
2944
|
3
|
2026-05-28T13:18:45.329624+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974325329_m1.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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":"ServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'ServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.021527778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.02013889,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"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":"45","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
85821
|
NULL
|
NULL
|
NULL
|
|
85822
|
2945
|
2
|
2026-05-28T13:18:16.912019+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974296912_m2.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"bounds":{"left":0.8753325,"top":0.915403,"width":0.11037234,"height":0.027134877},"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.8753325,"top":0.915403,"width":0.09740692,"height":0.027134877},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"bounds":{"left":0.8753325,"top":0.9481245,"width":0.03523936,"height":0.013567438},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11569149,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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.85638297,"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":"ServiceTest","depth":6,"bounds":{"left":0.87167555,"top":0.019952115,"width":0.043882977,"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 'ServiceTest'","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 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.010305851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.009640957,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"bounds":{"left":0.41589096,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"bounds":{"left":0.4245346,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"bounds":{"left":0.43550533,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"bounds":{"left":0.44414893,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"bounds":{"left":0.45279256,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"bounds":{"left":0.4637633,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"bounds":{"left":0.47473404,"top":0.09896249,"width":0.024268618,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"bounds":{"left":0.5013298,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"bounds":{"left":0.51230055,"top":0.09896249,"width":0.029587766,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"bounds":{"left":0.7237367,"top":0.09896249,"width":0.02825798,"height":0.01915403},"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":"45","depth":4,"bounds":{"left":0.6938165,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.70611703,"top":0.123703115,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"bounds":{"left":0.71542555,"top":0.123703115,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","depth":4,"bounds":{"left":0.72706115,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.12210695,"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.7463431,"top":0.12210695,"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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85821
|
2944
|
2
|
2026-05-28T13:18:14.813538+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974294813_m1.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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":"ServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'ServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.021527778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.02013889,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"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":"45","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
85820
|
2945
|
1
|
2026-05-28T13:17:46.403955+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974266403_m2.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"bounds":{"left":0.8753325,"top":0.915403,"width":0.11037234,"height":0.027134877},"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.8753325,"top":0.915403,"width":0.09740692,"height":0.027134877},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"bounds":{"left":0.8753325,"top":0.9481245,"width":0.03523936,"height":0.013567438},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11569149,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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.85638297,"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":"ServiceTest","depth":6,"bounds":{"left":0.87167555,"top":0.019952115,"width":0.043882977,"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 'ServiceTest'","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 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.010305851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.009640957,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"bounds":{"left":0.41589096,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"bounds":{"left":0.4245346,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"bounds":{"left":0.43550533,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"bounds":{"left":0.44414893,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"bounds":{"left":0.45279256,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"bounds":{"left":0.4637633,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"bounds":{"left":0.47473404,"top":0.09896249,"width":0.024268618,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"bounds":{"left":0.5013298,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"bounds":{"left":0.51230055,"top":0.09896249,"width":0.029587766,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"bounds":{"left":0.7237367,"top":0.09896249,"width":0.02825798,"height":0.01915403},"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":"45","depth":4,"bounds":{"left":0.6938165,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.70611703,"top":0.123703115,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"bounds":{"left":0.71542555,"top":0.123703115,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","depth":4,"bounds":{"left":0.72706115,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.12210695,"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.7463431,"top":0.12210695,"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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
85812
|
NULL
|
NULL
|
NULL
|
|
85819
|
2944
|
1
|
2026-05-28T13:17:44.322182+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974264322_m1.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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":"ServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'ServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.016666668,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.021527778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.02013889,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"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":"45","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
8102978660827784789
|
-6520523836324422875
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
...
|
85803
|
NULL
|
NULL
|
NULL
|
|
85818
|
2945
|
0
|
2026-05-28T13:17:15.872549+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779974235872_m2.jpg...
|
PhpStorm
|
faVsco.js – ServiceTest.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
1 file committed
JY-20963 add tests coverage
text/html
text/html
text/html
Edit Commit Message…
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the pr...
|
[{"role":"AXTextField","text [{"role":"AXTextField","text":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","depth":3,"bounds":{"left":0.8753325,"top":0.8387869,"width":0.11037234,"height":0.027134877},"on_screen":true,"value":"Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.8753325,"top":0.8387869,"width":0.09740692,"height":0.027134877},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"View pull request","depth":2,"bounds":{"left":0.8753325,"top":0.87150836,"width":0.03523936,"height":0.013567438},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1 file committed","depth":2,"bounds":{"left":0.8753325,"top":0.91300875,"width":0.100398935,"height":0.013567438},"on_screen":true,"role_description":"text"},{"role":"AXTextField","text":"JY-20963 add tests coverage","depth":3,"bounds":{"left":0.8753325,"top":0.92897046,"width":0.11037234,"height":0.013567438},"on_screen":true,"value":"JY-20963 add tests coverage","help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"bounds":{"left":0.8753325,"top":0.92897046,"width":0.061502658,"height":0.013567438},"on_screen":true,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextField","text":"text/html","depth":4,"on_screen":false,"help_text":"text/html","role_description":"text field","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Edit Commit Message…","depth":2,"bounds":{"left":0.8753325,"top":0.9481245,"width":0.048204787,"height":0.013567438},"on_screen":true,"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"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":"#12121 on JY-20963-fix-import-on-deleted-entity, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.11569149,"height":0.025538707},"on_screen":true,"help_text":"Pull request #12121 exists for current branch JY-20963-fix-import-on-deleted-entity, but pull request details loading failed","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.85638297,"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":"ServiceTest","depth":6,"bounds":{"left":0.87167555,"top":0.019952115,"width":0.043882977,"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 'ServiceTest'","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 'ServiceTest'","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":"Built-in Preview","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":"Chrome","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":"Firefox","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":"Safari","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":"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":"3","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.007978723,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"32","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.010305851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"81","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.009640957,"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\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Tests\\Unit\\Services\\Crm\\Salesforce;\n\nuse Illuminate\\Database\\Eloquent\\Relations\\HasMany;\nuse Illuminate\\Events\\Dispatcher;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Jiminny\\Component\\Country\\CountriesMap;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Enums\\CrmObject;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\NoResultsException;\nuse Jiminny\\Integrations\\PlaybookResolver;\nuse Jiminny\\Models\\Activity;\nuse Jiminny\\Models\\Contact;\nuse Jiminny\\Models\\Crm\\Configuration;\nuse Jiminny\\Models\\Crm\\Profile;\nuse Jiminny\\Models\\Opportunity;\nuse Jiminny\\Models\\Playbook;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\TeamSettings;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\Crm\\ContactRoleRepository;\nuse Jiminny\\Repositories\\Crm\\FieldDataRepository;\nuse Jiminny\\Repositories\\Crm\\ProfileRepository;\nuse Jiminny\\Services\\Avatar\\ProspectPhotoPathService;\nuse Jiminny\\Services\\Crm\\Salesforce\\Client;\nuse Jiminny\\Services\\Crm\\Salesforce\\PayloadBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryBuilder;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryHandler;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryIterator;\nuse Jiminny\\Services\\Crm\\Salesforce\\QueryResults;\nuse Jiminny\\Services\\Crm\\Salesforce\\Service;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse Tests\\TestCase;\nuse Tests\\Unit\\Traits\\TestPrivateMethod;\n\nclass ServiceTest extends TestCase\n{\n use TestPrivateMethod;\n\n public function testFetchAndAssociateRelatedActivity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $payloadBuilder->method('addCustomLogicFieldsPayload')\n ->willReturnCallback(function ($activity, $payload) {\n return $payload;\n });\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])\n ->getMock();\n\n $serviceMock->expects($this->once())\n ->method('fetchRelatedActivity')\n ->willReturn([\n 'Id' => 'testId',\n 'Type' => null,\n 'OwnerId' => 'testerUser',\n 'Description' => 'Test description',\n ]);\n\n $user = $this->createMock(User::class);\n $team = $this->createMock(Team::class);\n $user->method('getAttribute')->with('team')->willReturn($team);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityField')->willReturn(null);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('getPlaybookCategory');\n\n $serviceMock->expects($this->never())\n ->method('updateRecord');\n\n $fieldDataRepository = $this->createMock(FieldDataRepository::class);\n $fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));\n app()->instance(FieldDataRepository::class, $fieldDataRepository);\n\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $config->method('profiles')->willReturn($profilesRelation);\n\n $serviceMock->config = $config;\n $serviceMock->profile = null;\n\n $actualStartTime = \\Carbon\\Carbon::now();\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['update', 'hasProspect'])\n ->getMock();\n\n $activity->method('update')->willReturn(true);\n $activity->method('hasProspect')->willReturn(true);\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->provider = Activity::PROVIDER_TWILIO;\n $activity->lead_id = 1;\n $activity->user_id = 0;\n $activity->id_string = 'test-activity-id';\n $activity->user = $user;\n\n $activity->actual_start_time = $actualStartTime;\n $activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';\n\n app()->bind(PlaybookResolver::class, function () use ($user) {\n $playbook = $this->createMock(Playbook::class);\n $playbookResolver = $this->createMock(PlaybookResolver::class);\n $playbookResolver->expects($this->once())\n ->method('resolvePlaybookByUser')\n ->with($user)\n ->willReturn($playbook);\n\n return $playbookResolver;\n });\n\n $data = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertInstanceOf(Activity::class, $data);\n $this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());\n $this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());\n }\n\n public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])\n ->getMock();\n\n $user = $this->createMock(User::class);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n $playbook->method('getId')->willReturn(123);\n\n $serviceMock->expects($this->once())\n ->method('getPlaybook')\n ->with($user)\n ->willReturn($playbook);\n\n $serviceMock->expects($this->never())\n ->method('fetchRelatedActivity');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(true);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n $activity->user = $user;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_SOFTPHONE;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $serviceMock = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->getMock();\n\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = null;\n $activity->scheduled_start_time = null;\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['getPlaybook'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('getPlaybook');\n\n $activity = $this->getMockBuilder(Activity::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['hasProspect', 'getUuid'])\n ->getMock();\n\n $activity->method('hasProspect')->willReturn(false);\n $activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');\n $activity->type = Activity::TYPE_CONFERENCE;\n $activity->actual_start_time = \\Carbon\\Carbon::now();\n\n $result = $serviceMock->fetchAndAssociateRelatedActivity($activity);\n\n $this->assertNull($result);\n }\n\n public function testMatchExactlyByEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods([])\n ->getMock();\n\n $profile = new Profile();\n $profile->setAttribute('id', bin2hex(random_bytes(8)));\n $serviceMock->profile = $profile;\n\n $team = $this->createMock(Team::class);\n $serviceMock->team = $team;\n\n $data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . 'test_email@testserver.com');\n\n $this->assertEquals(null, $data);\n }\n\n public function testMatchDomainFromEmail(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $config = $this->createMock(Configuration::class);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('search')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCrmData'])\n ->getMock();\n\n $profile = new Profile();\n $profile->account_fields = 'Field1, Field2, Field3';\n $serviceMock->profile = $profile;\n\n $serviceMock->expects($this->once())\n ->method('convertCrmData')\n ->willReturn(['test']);\n\n $this->app->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildMatchByDomainQuery')\n ->with('test_email@testserver.com')\n ->willReturn('FIND {test_email@testserver.com} IN ALL FIELDS RETURNING Account(Id)');\n\n return $queryBuilder;\n });\n\n $team = $this->createMock(Team::class);\n\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $data = $serviceMock->matchByDomain('test_email@testserver.com');\n\n $this->assertEquals(['test'], $data);\n }\n\n public function testBuildTaskSearchFields(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)\n );\n\n $fields = $service->buildTaskSearchFields();\n\n $expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];\n\n $this->assertEquals($expectedFields, $fields);\n }\n\n public function testMapCrmObjects(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),\n );\n\n $sampleTask = [\n 'WhoId' => '003sampleWhoId',\n 'AccountId' => 'sampleAccountId',\n 'WhatId' => 'sampleWhatId',\n ];\n\n $activityData = $service->mapCrmObjects($sampleTask);\n\n $expectedActivityData = [\n 'contact' => '003sampleWhoId',\n 'account' => 'sampleAccountId',\n 'opportunity' => 'sampleWhatId',\n ];\n\n $this->assertEquals($expectedActivityData, $activityData);\n }\n\n public function testGetInstalledAppVersion(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n $queryIterator = $this->createMock(QueryIterator::class);\n $queryIterator->expects($this->any())\n ->method('current')->willReturn([\n 'SubscriberPackageVersion' => [\n 'MajorVersion' => '1',\n 'MinorVersion' => '0',\n 'PatchVersion' => '1',\n 'BuildNumber' => '0',\n ],\n ]);\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('metadata')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))\n ->getMock();\n\n $version = $serviceMock->getInstalledAppVersion();\n\n $this->assertEquals('1010', $version);\n }\n\n public function testSyncProfiles(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testSyncProfilesEmailIsNull(): void\n {\n $userToSearch = $this->createMock(User::class);\n\n $salesforceUser = [\n 'Email' => null,\n ];\n\n app()->bind(QueryBuilder::class, function () {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with(null)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->exactly(2))\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $team = $this->createMock(Team::class);\n $user = $this->createMock(User::class);\n $this->mockTeamRepository($team, $salesforceUser, $user, false);\n\n $config = $this->createMock(Configuration::class);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n\n $profile = $serviceMock->syncProfiles(null);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesUserToSearchMatchesCurrentUser(): void\n {\n $userToSearch = $this->createMock(User::class);\n $userToSearch->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $team = $this->createMock(Team::class);\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n ];\n\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->with('SELECT * FROM Users')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n\n $user = $this->createMock(User::class);\n $user->expects($this->exactly(2))\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user);\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertInstanceOf(Profile::class, $profile);\n }\n\n public function testSyncProfilesWithCustomValidation(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n $config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()\n ->method('getId')\n ->willReturn(1);\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'CustomValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $user = $this->createMock(User::class);\n $user->expects($this->once())\n ->method('getId')\n ->willReturn(123);\n\n $this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);\n\n $this->mockProfileRepository($user);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $profile = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($profile);\n }\n\n public function testSyncProfilesWithCustomValidationFailing(): void\n {\n $userToSearch = null;\n\n $team = $this->createMock(Team::class);\n $config = $this->createMockedConfiguration();\n\n $salesforceUser = [\n 'Email' => 'test@example.com',\n 'UserPreferencesLightningExperiencePreferred' => true,\n 'CallCenterId' => '123',\n 'Id' => '456',\n 'ProfileId' => '789',\n 'CustomField' => 'WrongValue',\n ];\n\n $customRules = [\n ['field' => 'CustomField', 'value' => 'CustomValue'],\n ];\n\n $this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);\n\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->never())\n ->method('updateOrCreateProfile');\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $team;\n $serviceMock->config = $config;\n $result = $serviceMock->syncProfiles($userToSearch);\n\n $this->assertNull($result);\n }\n\n public function testGetContactRolesFromCrm(): void\n {\n $contactRoles = [\n [\n 'Id' => '1',\n 'ContactId' => 'Contact1',\n 'OpportunityId' => 'Opportunity1',\n 'Opportunity' => ['OwnerId' => 'Owner1'],\n 'IsPrimary' => true,\n 'Role' => 'Decision Maker',\n ],\n ];\n\n $expectedResponse = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n $this->bindQueryIterator($contactRoles);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals($expectedResponse, $data);\n }\n\n public function testGetContactRolesFromCrmNoResult(): void\n {\n $this->bindQueryIterator([]);\n\n $serviceMock = $this->getServiceMock();\n\n $data = $serviceMock->getContactRolesFromCrm(now()->subDay());\n\n $this->assertEquals([], $data);\n }\n\n public function testSyncContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'contactId' => 'Contact1',\n 'opportunityId' => 'Opportunity1',\n 'ownerId' => 'Owner1',\n 'isPrimary' => true,\n 'role' => 'Decision Maker',\n ],\n ];\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('saveContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock([\n 'getContactRolesFromCrm',\n 'syncRemotelyDeletedContactRoles',\n 'syncContact',\n 'syncOpportunity',\n ]);\n\n $config = $this->createMock(Configuration::class);\n $hasMany = $this->createMock(HasManyExtended::class);\n $hasMany->expects($this->exactly(2))\n ->method('where')\n ->willReturn($hasMany);\n\n $hasMany->expects($this->exactly(2))\n ->method('first')\n ->willReturn(\n $this->createMock(Contact::class),\n $this->createMock(Opportunity::class)\n );\n\n $config->expects($this->once())\n ->method('contacts')\n ->willReturn($hasMany);\n $config->expects($this->once())\n ->method('opportunities')\n ->willReturn($hasMany);\n\n $serviceMock->config = $config;\n\n $serviceMock->expects($this->once())\n ->method('getContactRolesFromCrm')\n ->willReturn($contactRoles);\n\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedContactRoles');\n\n $data = $serviceMock->syncContactRoles(now()->subDay());\n\n $this->assertEquals(1, $data);\n }\n\n public function testSyncRemotelyDeletedContactRoles(): void\n {\n $contactRoles = [\n [\n 'id' => '1',\n 'crm_provider_id' => '1',\n ],\n ];\n\n app()->bind(QueryHandler::class, function () use ($contactRoles) {\n $queryResults = new QueryResults($contactRoles, 1, true, null);\n\n $handler = $this->createMock(QueryHandler::class);\n $handler->method('queryDeleted')\n ->willReturn($queryResults);\n\n return $handler;\n });\n\n app()->bind(ContactRoleRepository::class, function () {\n $contactRoleRepository = $this->createMock(ContactRoleRepository::class);\n $contactRoleRepository->expects($this->once())\n ->method('deleteContactRoles');\n\n return $contactRoleRepository;\n });\n\n $serviceMock = $this->getServiceMock();\n $serviceMock->team = $this->createMock(Team::class);\n\n $data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);\n\n $this->assertTrue($data);\n }\n\n private function bindQueryIterator(array $queryResult): void\n {\n /** @var Client $client */\n $client = $this->createMock(Client::class);\n $queryIterator = new QueryIterator(\n $client,\n new QueryResults($queryResult, 1, true, null)\n );\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n public static function getOpportunitySortOrderDataProvider(): array\n {\n return [\n 'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],\n 'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],\n 'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],\n 'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],\n 'default' => ['unknown', ['LastModifiedDate DESC', true]],\n ];\n }\n\n private function createMockedConfiguration(): Configuration\n {\n $config = $this->createMock(Configuration::class);\n $profilesRelation = $this->getMockBuilder(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class)\n ->disableOriginalConstructor()\n ->onlyMethods(['get'])\n ->addMethods(['where', 'first'])\n ->getMock();\n $profilesRelation->method('where')->willReturnSelf();\n $profilesRelation->method('get')->willReturn(collect([]));\n $profilesRelation->method('first')->willReturn(null);\n $config->method('profiles')->willReturn($profilesRelation);\n\n return $config;\n }\n\n private function getServiceMock(array $onlyMethods = []): MockObject&Service\n {\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods($onlyMethods)\n ->getMock();\n\n $serviceMock->profile = $this->createMock(Profile::class);\n\n return $serviceMock;\n }\n\n private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void\n {\n app()->bind(QueryBuilder::class, function () use ($userToSearch) {\n $queryBuilder = $this->createMock(QueryBuilder::class);\n $queryBuilder->expects($this->once())\n ->method('buildGetUsersQuery')\n ->with($userToSearch)\n ->willReturn('SELECT * FROM Users');\n\n return $queryBuilder;\n });\n\n $queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));\n\n app()->bind(QueryHandler::class, function () use ($queryIterator) {\n $handler = $this->createMock(QueryHandler::class);\n $handler->expects($this->any())\n ->method('query')\n ->willReturn($queryIterator);\n\n return $handler;\n });\n }\n\n private function mockTeamRepository(\n Team $team,\n array $salesforceUser,\n ?User $user = null,\n bool $userSearch = true,\n array $customRules = []\n ): void {\n $teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);\n\n if ($userSearch) {\n $teamRepository->expects($this->once())\n ->method('findActiveTeamMemberByEmail')\n ->with($team, $salesforceUser['Email'])\n ->willReturn($user);\n }\n\n $teamSettings = $this->createMock(TeamSettings::class);\n $teamSettings->method('getValueType')\n ->willReturn('array');\n\n $teamSettings->method('getValue')\n ->willReturn(json_encode($customRules));\n\n $teamRepository->expects($this->once())\n ->method('getTeamSetting')\n ->with($team, 'custom_profile_validation')\n ->willReturn($teamSettings);\n\n app()->bind(TeamRepository::class, function () use ($teamRepository) {\n return $teamRepository;\n });\n }\n\n private function mockProfileRepository(User $user): void\n {\n $profileRepository = $this->createMock(ProfileRepository::class);\n $profileRepository->expects($this->once())\n ->method('updateOrCreateProfile')\n ->with(\n $user,\n [\n 'crm_configuration_id' => 1,\n 'crm_provider_id' => '456',\n ],\n [\n 'user_id' => 123,\n 'edition' => Profile::EDITION_LIGHTNING,\n 'has_external_cti' => true,\n 'crm_profile_id' => '789',\n ]\n )\n ->willReturn(new Profile());\n\n $this->app->instance(ProfileRepository::class, $profileRepository);\n }\n\n public function testBuildEnhancedNoteDecodesHtmlEntities(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-123');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');\n\n $bodyWithEntities = 'Welch's current challenges and Facebook's Club';\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithEntities,\n 'object-id-789',\n ]);\n\n $this->assertEquals('note-id-123', $result);\n }\n\n public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-456');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<script>', $decoded);\n\n return 'note-id-456';\n }\n\n return 'link-id-789';\n });\n\n $bodyWithMixedContent = \"Welch's and <script>alert('xss')</script>\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithMixedContent,\n 'object-id-123',\n ]);\n\n $this->assertEquals('note-id-456', $result);\n }\n\n public function testBuildEnhancedNoteConvertsLineBreaks(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-789');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringNotContainsString('<br />', $decoded);\n\n return 'note-id-789';\n }\n\n return 'link-id-012';\n });\n\n $bodyWithLineBreaks = \"Line 1\\nLine 2\\nLine 3\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Test Title',\n $bodyWithLineBreaks,\n 'object-id-456',\n ]);\n\n $this->assertEquals('note-id-789', $result);\n }\n\n public function testBuildEnhancedNoteHandlesComplexScenario(): void\n {\n $service = $this->getServiceMock(['createRecord']);\n\n $profile = new Profile();\n $profile->setAttribute('crm_provider_id', 'owner-complex');\n $service->profile = $profile;\n\n $service->expects($this->exactly(2))\n ->method('createRecord')\n ->willReturnCallback(function ($type, $data) {\n if ($type === 'ContentNote') {\n $decoded = base64_decode($data['Content']);\n\n $this->assertStringContainsString(\"Welch's\", $decoded);\n $this->assertStringContainsString(\"Facebook's Club\", $decoded);\n $this->assertStringContainsString(\"Arctics'\", $decoded);\n $this->assertStringNotContainsString(''', $decoded);\n $this->assertStringNotContainsString('&#039;', $decoded);\n $this->assertStringContainsString('<br>', $decoded);\n $this->assertStringContainsString('<', $decoded);\n $this->assertStringContainsString('>', $decoded);\n\n return 'note-complex';\n }\n\n return 'link-complex';\n });\n\n $complexBody = \"Summary:\\n---------\\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\\n\\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.\";\n\n $result = $this->invokePrivateMethod('buildEnhancedNote', $service, [\n 'Jiminny Transcription Summary',\n $complexBody,\n 'task-id-001',\n ]);\n\n $this->assertEquals('note-complex', $result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-123');\n $serviceMock->team = $team;\n\n // Expect syncRemotelyDeletedObjects to be called once and succeed\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not throw any exceptions\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::ACCOUNT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-456');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $reflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Sync failed due to API error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::CONTACT)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct message and parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'contact',\n 'teamId' => 'team-uuid-456',\n 'reason' => 'Sync failed due to API error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::CONTACT);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-789');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflection = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Network timeout');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with(\\Jiminny\\Enums\\CrmObject::OPPORTUNITY)\n ->willThrowException($exception);\n\n // Additional log parameters\n $logParams = [\n 'syncType' => 'full',\n 'batchSize' => 100,\n ];\n\n // Expect warning to be logged with merged parameters\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => 'opportunity',\n 'teamId' => 'team-uuid-789',\n 'reason' => 'Network timeout',\n 'syncType' => 'full',\n 'batchSize' => 100,\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n // Should not re-throw the exception, just log it\n $method->invoke($serviceMock, \\Jiminny\\Enums\\CrmObject::OPPORTUNITY, $logParams);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n /**\n * @dataProvider crmObjectProvider\n */\n public function testSyncRemotelyDeletedObjectsWithErrorHandlingDifferentCrmObjects(\\Jiminny\\Enums\\CrmObject $crmObject): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['syncRemotelyDeletedObjects'])\n ->getMock();\n\n // Mock team\n $team = $this->createMock(Team::class);\n $team->method('getUuid')->willReturn('team-uuid-test');\n $serviceMock->team = $team;\n\n // Mock logger to verify warning is logged\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n\n // Use reflection to set the protected logger property\n $loggerReflectionClass = new \\ReflectionClass($serviceMock);\n $loggerProperty = $loggerReflectionClass->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($serviceMock, $logger);\n\n $exception = new \\Exception('Test error');\n\n // Expect syncRemotelyDeletedObjects to throw an exception\n $serviceMock->expects($this->once())\n ->method('syncRemotelyDeletedObjects')\n ->with($crmObject)\n ->willThrowException($exception);\n\n // Expect warning to be logged with correct entity type\n $logger->expects($this->once())\n ->method('warning')\n ->with(\n '[Salesforce] Remotely deleted objects sync failed',\n [\n 'objectType' => $crmObject->value,\n 'teamId' => 'team-uuid-test',\n 'reason' => 'Test error',\n ]\n );\n\n // Call the protected method using reflection\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $crmObject);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testHandleObjectDeletionWithDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Account::class);\n $crmData = ['IsDeleted' => true];\n\n $serviceMock->expects($this->once())\n ->method('deleteCrmObject')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testHandleObjectDeletionWithNonDeletedEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['deleteCrmObject'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Contact::class);\n $crmData = ['IsDeleted' => false];\n\n $serviceMock->expects($this->never())\n ->method('deleteCrmObject');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('handleObjectDeletion');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity, $crmData);\n }\n\n public function testDeleteCrmObjectWithValidEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $entity = $this->createMock(\\Jiminny\\Models\\Lead::class);\n $entity->expects($this->once())->method('delete');\n\n $serviceMock->expects($this->once())\n ->method('dispatchDeleteCrmObjectJob')\n ->with($entity);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, $entity);\n }\n\n public function testDeleteCrmObjectWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n /** @var Service&MockObject $serviceMock */\n $serviceMock = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['dispatchDeleteCrmObjectJob'])\n ->getMock();\n\n $serviceMock->expects($this->never())\n ->method('dispatchDeleteCrmObjectJob');\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($serviceMock);\n $method = $reflection->getMethod('deleteCrmObject');\n $method->setAccessible(true);\n\n $method->invoke($serviceMock, null);\n }\n\n public function testDispatchDeleteCrmObjectJobWithNullEntity(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n $method->setAccessible(true);\n\n // Should return early without dispatching - no exception expected\n $method->invoke($service, null);\n\n $this->assertTrue(true); // Test completed successfully\n }\n\n public function testDispatchDeleteCrmObjectJobWithUnsupportedEntity(): void\n {\n $this->expectException(\\TypeError::class);\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n $unsupportedEntity = $this->createMock(\\stdClass::class);\n\n // Use reflection to call the protected method\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('dispatchDeleteCrmObjectJob');\n\n // This will throw TypeError due to union type constraint\n $method->invoke($service, $unsupportedEntity);\n }\n\n public function testHandleEntityDeletionByProviderIdMethodExists(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Test that the method exists and is accessible via reflection\n $reflection = new \\ReflectionClass($service);\n $method = $reflection->getMethod('handleEntityDeletionByProviderId');\n $method->setAccessible(true);\n\n // Verify method exists and has correct parameters\n $this->assertTrue($method->isProtected());\n $this->assertEquals(2, $method->getNumberOfParameters());\n\n $parameters = $method->getParameters();\n $this->assertEquals('targetEntity', $parameters[0]->getName());\n $this->assertEquals('crmData', $parameters[1]->getName());\n }\n\n public function testSyncRemotelyDeletedObjectsWithNoResults(): void\n {\n // Create a real service instance to avoid mock property issues\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to throw NoResultsException\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willThrowException(new NoResultsException('No results'));\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithEmptyResults(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return empty results\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn([]);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Opportunity')\n ->willReturn($queryResult);\n\n // Set the queryHandler using reflection on the real service\n $reflection = new \\ReflectionClass($service);\n $queryHandlerProperty = $reflection->getProperty('queryHandler');\n $queryHandlerProperty->setAccessible(true);\n $queryHandlerProperty->setValue($service, $queryHandler);\n\n $result = self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::OPPORTUNITY]);\n\n $this->assertFalse($result);\n }\n\n public function testSyncRemotelyDeletedObjectsWithUnsupportedCrmObject(): void\n {\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = new Service(\n client: $client,\n payloadBuilder: $payloadBuilder,\n eventDispatcher: $eventDispatcher,\n countriesMap: $countriesMap,\n prospectPhotoPathService: $prospectPhotoPathService,\n );\n\n // Mock queryHandler to return some deleted objects so we reach the match statement\n $deletedObjects = [\n ['id' => 'task1'],\n ['id' => 'task2'],\n ];\n $queryResult = $this->createMock(QueryResults::class);\n $queryResult->method('getResults')->willReturn($deletedObjects);\n\n $queryHandler = $this->createMock(QueryHandler::class);\n $queryHandler->expects($this->once())\n ->method('queryDeleted')\n ->with('Task') // ucfirst('task') = 'Task'\n ->willReturn($queryResult);\n\n self::setPrivateProperty($service, 'queryHandler', $queryHandler);\n\n $this->expectException(InvalidArgumentException::class);\n $this->expectExceptionMessage('Unsupported CrmObject: task');\n\n self::invokePrivateMethod('syncRemotelyDeletedObjects', $service, [CrmObject::TASK]);\n }\n\n public static function crmObjectProvider(): array\n {\n return [\n 'Account' => [CrmObject::ACCOUNT],\n 'Contact' => [CrmObject::CONTACT],\n 'Lead' => [CrmObject::LEAD],\n 'Opportunity' => [CrmObject::OPPORTUNITY],\n ];\n }\n\n public function testVerifyTaskExistsReturnsTrue(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsTrueForEvent(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:event-123', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('event-123');\n $activity->method('getId')->willReturn(456);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Event', 'event-123', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'event-123', 'IsDeleted' => false]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenDeleted(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-456', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-456');\n $activity->method('getId')->willReturn(789);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-456', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-456', 'IsDeleted' => true]);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNotFound(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-999', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-999');\n $activity->method('getId')->willReturn(999);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-999', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpNotFoundException('Task not found'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsReturnsFalseWhenNoPlaybook(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-no-playbook', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-no-playbook');\n $activity->method('getId')->willReturn(111);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn(null);\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testVerifyTaskExistsThrowsExceptionForTransientErrors(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-error', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-error');\n $activity->method('getId')->willReturn(888);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-error', ['Id', 'IsDeleted'])\n ->willThrowException(new \\RuntimeException('Network timeout'));\n\n $this->expectException(\\RuntimeException::class);\n $this->expectExceptionMessage('Network timeout');\n\n $service->verifyTaskExists($activity);\n }\n\n public function testVerifyTaskExistsCachesResults(): void\n {\n $cachedValue = null;\n Cache::shouldReceive('remember')\n ->twice()\n ->with('crm_task_exists:123:task-cached', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(function ($key, $ttl, $callback) use (&$cachedValue) {\n if ($cachedValue === null) {\n $cachedValue = $callback();\n }\n\n return $cachedValue;\n });\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-cached');\n $activity->method('getId')->willReturn(555);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-cached', ['Id', 'IsDeleted'])\n ->willReturn(['Id' => 'task-cached', 'IsDeleted' => false]);\n\n $result1 = $service->verifyTaskExists($activity);\n $result2 = $service->verifyTaskExists($activity);\n\n $this->assertTrue($result1);\n $this->assertTrue($result2);\n }\n\n public function testVerifyTaskExistsReturnsFalseForHttpBadRequestException(): void\n {\n Cache::shouldReceive('remember')\n ->once()\n ->with('crm_task_exists:123:task-400', 86400, \\Mockery::type('Closure'))\n ->andReturnUsing(fn ($key, $ttl, $callback) => $callback());\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $eventDispatcher = $this->createMock(Dispatcher::class);\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['getRecord', 'getPlaybookFromActivity'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->method('getId')->willReturn(123);\n\n self::setPrivateProperty($service, 'config', $config);\n\n $activity = $this->createMock(Activity::class);\n $activity->method('getCrmProviderId')->willReturn('task-400');\n $activity->method('getId')->willReturn(400);\n\n $playbook = $this->createMock(Playbook::class);\n $playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);\n\n $service->expects($this->once())\n ->method('getPlaybookFromActivity')\n ->with($activity)\n ->willReturn($playbook);\n\n $service->expects($this->once())\n ->method('getRecord')\n ->with('Task', 'task-400', ['Id', 'IsDeleted'])\n ->willThrowException(new \\Jiminny\\Exceptions\\HttpBadRequestException('Bad request'));\n\n $result = $service->verifyTaskExists($activity);\n\n $this->assertFalse($result);\n }\n\n public function testImportOpportunitySkipsWhenNoProfileAndNoAccount(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-1',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-no-profile',\n // No AccountId\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $countriesMap = $this->createMock(CountriesMap::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-no-profile')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-1']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property to avoid \"must not be accessed before initialization\" error\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsNullWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('handleEntityDeletionByProviderId')\n ->with($contactsRelation, $crmData);\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactSkipsWritesWhenIsDeleted(): void\n {\n $crmData = ['Id' => 'SF-CON-DEL-2', 'IsDeleted' => true];\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n\n $config = $this->createMock(Configuration::class);\n $config->expects($this->once())->method('contacts')->willReturn($contactsRelation);\n\n $service = $this->getServiceMock(['handleEntityDeletionByProviderId']);\n $service->config = $config;\n\n $service->expects($this->once())->method('handleEntityDeletionByProviderId');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsTrashedContactAsNull(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-TRASHED',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Trashed Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(true);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n\n public function testImportContactReturnsContactWhenActive(): void\n {\n $crmData = [\n 'Id' => 'SF-CON-ACTIVE',\n 'IsDeleted' => false,\n 'OwnerId' => null,\n 'Name' => 'Active Contact',\n ];\n\n $contact = $this->createMock(Contact::class);\n $contact->method('trashed')->willReturn(false);\n\n $contactsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first', 'withTrashed'])\n ->onlyMethods(['updateOrCreate'])\n ->getMock();\n $contactsRelation->method('where')->willReturnSelf();\n $contactsRelation->method('withTrashed')->willReturnSelf();\n $contactsRelation->method('first')->willReturn(null);\n $contactsRelation->method('updateOrCreate')->willReturn($contact);\n\n $config = $this->createMock(Configuration::class);\n $config->method('contacts')->willReturn($contactsRelation);\n $config->method('accounts')->willReturn($contactsRelation);\n\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n $prospectPhotoPathService->method('getOrGeneratePhotoPath')->willReturn('photo.jpg');\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $this->createMock(CountriesMap::class),\n $prospectPhotoPathService,\n ])\n ->onlyMethods(['handleObjectDeletion'])\n ->getMock();\n\n $service->config = $config;\n $service->profile = $this->createMock(Profile::class);\n\n $team = $this->createMock(Team::class);\n $team->method('getAttribute')->with('id')->willReturn(1);\n $service->team = $team;\n\n $service->method('handleObjectDeletion');\n\n $result = self::invokePrivateMethod('importContact', $service, [$crmData]);\n\n $this->assertSame($contact, $result);\n }\n\n public static function resolveContactAccountProvider(): array\n {\n return [\n 'no AccountId returns null' => [[], null],\n 'AccountId present' => [['AccountId' => 'ACC-001'], 'ACC-001'],\n ];\n }\n\n /**\n * @dataProvider resolveContactAccountProvider\n */\n public function testResolveContactAccountWithNoAccountId(array $crmData, ?string $expectedId): void\n {\n $service = $this->getServiceMock(['syncAccount']);\n\n if ($expectedId === null) {\n $service->expects($this->never())->method('syncAccount');\n $config = $this->createMock(Configuration::class);\n $config->expects($this->never())->method('accounts');\n $service->config = $config;\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertNull($result);\n\n return;\n }\n\n $account = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->with('crm_provider_id', $expectedId)->willReturnSelf();\n $accountsRelation->method('first')->willReturn($account);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n $service->config = $config;\n\n $service->expects($this->never())->method('syncAccount');\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [$crmData]);\n $this->assertSame($account, $result);\n }\n\n public function testResolveContactAccountSyncsWhenNotFoundLocally(): void\n {\n $syncedAccount = $this->createMock(\\Jiminny\\Models\\Account::class);\n\n $accountsRelation = $this->getMockBuilder(HasMany::class)\n ->disableOriginalConstructor()\n ->addMethods(['where', 'first'])\n ->getMock();\n $accountsRelation->method('where')->willReturnSelf();\n $accountsRelation->method('first')->willReturn(null);\n\n $config = $this->createMock(Configuration::class);\n $config->method('accounts')->willReturn($accountsRelation);\n\n $service = $this->getServiceMock(['syncAccount']);\n $service->config = $config;\n\n $service->expects($this->once())\n ->method('syncAccount')\n ->with('ACC-MISSING')\n ->willReturn($syncedAccount);\n\n $result = self::invokePrivateMethod('resolveContactAccount', $service, [['AccountId' => 'ACC-MISSING']]);\n\n $this->assertSame($syncedAccount, $result);\n }\n\n public static function resolveContactCountryCodeProvider(): array\n {\n return [\n 'valid MailingCountryCode' => [['MailingCountryCode' => 'GB'], true, null, 'GB'],\n 'invalid MailingCountryCode falls to null' => [['MailingCountryCode' => 'XX'], false, null, null],\n 'no code, uses MailingCountry converted' => [['MailingCountry' => 'Germany'], null, 'DE', 'DE'],\n 'no code, country name null, uses account' => [['MailingCountry' => 'Unknown'], null, null, 'US'],\n 'no code, no country at all' => [[], null, null, null],\n ];\n }\n\n /**\n * @dataProvider resolveContactCountryCodeProvider\n */\n public function testResolveContactCountryCode(\n array $crmData,\n ?bool $countryExists,\n ?string $convertedCode,\n ?string $expected\n ): void {\n $countriesMap = $this->createMock(CountriesMap::class);\n if ($countryExists !== null) {\n $countriesMap->method('countryExists')->willReturn($countryExists);\n }\n\n $service = $this->getMockBuilder(Service::class)\n ->setConstructorArgs([\n $this->createMock(Client::class),\n $this->createMock(PayloadBuilder::class),\n $this->createMock(Dispatcher::class),\n $countriesMap,\n $this->createMock(ProspectPhotoPathService::class),\n ])\n ->onlyMethods(['convertCountryNameToCode'])\n ->getMock();\n\n $service->profile = $this->createMock(Profile::class);\n\n if (isset($crmData['MailingCountry'])) {\n $service->expects($this->once())\n ->method('convertCountryNameToCode')\n ->with($crmData['MailingCountry'])\n ->willReturn($convertedCode);\n } else {\n $service->expects($this->never())->method('convertCountryNameToCode');\n }\n\n $account = null;\n if ($expected === 'US') {\n $account = new \\Jiminny\\Models\\Account();\n $account->setAttribute('country_code', 'US');\n }\n\n $result = self::invokePrivateMethod('resolveContactCountryCode', $service, [$crmData, $account]);\n\n $this->assertSame($expected, $result);\n }\n\n public static function parseContactPhoneProvider(): array\n {\n return [\n 'empty Phone returns empty' => [['Phone' => ''], null, [[], null]],\n 'no Phone key returns empty' => [[], null, [[], null]],\n ];\n }\n\n /**\n * @dataProvider parseContactPhoneProvider\n */\n public function testParseContactPhoneWithEmptyPhone(array $crmData, ?string $countryCode, array $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactPhone', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactPhoneWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, [null, $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('+12025551234', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public function testParseContactPhoneWithExtension(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 42'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertSame('42', $ext);\n }\n\n public function testParseContactPhoneExtIsTruncatedTo10Chars(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '+12025551234 ext. 12345678901'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['US', $crmData]);\n\n $this->assertNotNull($ext);\n $this->assertLessThanOrEqual(10, strlen($ext));\n }\n\n public function testParseContactPhoneWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['Phone' => '02075551234'];\n\n [$parsedNumber, $ext] = self::invokePrivateMethod('parseContactPhone', $service, ['GB', $crmData]);\n\n $this->assertArrayHasKey('phone', $parsedNumber);\n $this->assertStringStartsWith('+44', $parsedNumber['phone']);\n $this->assertNull($ext);\n }\n\n public static function parseContactMobileProvider(): array\n {\n return [\n 'empty MobilePhone returns null' => [['MobilePhone' => ''], null, null],\n 'no MobilePhone key returns null' => [[], null, null],\n ];\n }\n\n /**\n * @dataProvider parseContactMobileProvider\n */\n public function testParseContactMobileWithEmptyPhone(array $crmData, ?string $countryCode, ?string $expected): void\n {\n $service = $this->getServiceMock();\n $result = self::invokePrivateMethod('parseContactMobile', $service, [$countryCode, $crmData]);\n $this->assertSame($expected, $result);\n }\n\n public function testParseContactMobileWithValidNumber(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '+12025550199'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertSame('+12025550199', $result);\n }\n\n public function testParseContactMobileIsTruncatedTo25Chars(): void\n {\n $service = $this->getServiceMock();\n $longNumber = '+1202555019912345678901234';\n $crmData = ['MobilePhone' => $longNumber];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, [null, $crmData]);\n\n $this->assertNotNull($result);\n $this->assertLessThanOrEqual(25, strlen($result));\n }\n\n public function testParseContactMobileWithCountryCode(): void\n {\n $service = $this->getServiceMock();\n $crmData = ['MobilePhone' => '07911123456'];\n\n $result = self::invokePrivateMethod('parseContactMobile', $service, ['GB', $crmData]);\n\n $this->assertNotNull($result);\n $this->assertStringStartsWith('+44', $result);\n }\n\n public function testImportOpportunitySkipsWhenProfileNotFound(): void\n {\n $crmData = [\n 'Id' => 'SF-NO-USER-2',\n 'Name' => 'Test Opportunity',\n 'OwnerId' => 'owner-not-found',\n // No AccountId - avoid complex account processing\n ];\n\n $client = $this->createMock(Client::class);\n $payloadBuilder = $this->createMock(PayloadBuilder::class);\n $eventDispatcher = $this->createMock(\\Illuminate\\Events\\Dispatcher::class); // ← ADD THIS\n $countriesMap = $this->createMock(CountriesMap::class);\n $prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);\n\n\n $service = new Service(\n $client,\n $payloadBuilder,\n $eventDispatcher,\n $countriesMap,\n $prospectPhotoPathService\n );\n\n $config = $this->createMock(Configuration::class);\n\n // Mock profiles relation returning null (no profile found)\n $profilesRelation = \\Mockery::mock(\\Illuminate\\Database\\Eloquent\\Relations\\HasMany::class);\n $profilesRelation->shouldReceive('where')->with('crm_provider_id', 'owner-not-found')->andReturnSelf();\n $profilesRelation->shouldReceive('first')->andReturn(null);\n\n $config->expects($this->once())\n ->method('profiles')\n ->willReturn($profilesRelation);\n\n $team = $this->createMock(Team::class);\n $team->method('getId')->willReturn(1);\n\n $logger = $this->createMock(\\Psr\\Log\\LoggerInterface::class);\n $logger->expects($this->once())\n ->method('error')\n ->with(\n '[Salesforce] | Skip import, no user_id found',\n ['id' => 'SF-NO-USER-2']\n );\n\n $reflection = new \\ReflectionClass($service);\n\n $configProperty = $reflection->getProperty('config');\n $configProperty->setAccessible(true);\n $configProperty->setValue($service, $config);\n\n $teamProperty = $reflection->getProperty('team');\n $teamProperty->setAccessible(true);\n $teamProperty->setValue($service, $team);\n\n $loggerProperty = $reflection->getProperty('logger');\n $loggerProperty->setAccessible(true);\n $loggerProperty->setValue($service, $logger);\n\n // Initialize profile property\n $profileProperty = $reflection->getProperty('profile');\n $profileProperty->setAccessible(true);\n $profileProperty->setValue($service, null);\n\n $result = self::invokePrivateMethod('importOpportunity', $service, [$crmData]);\n\n $this->assertNull($result);\n }\n}\n\nclass HasManyExtended extends HasMany\n{\n public function where()\n {\n }\n\n public function first()\n {\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"bounds":{"left":0.41589096,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"bounds":{"left":0.4245346,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"bounds":{"left":0.43550533,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"bounds":{"left":0.44414893,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"bounds":{"left":0.45279256,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"bounds":{"left":0.4637633,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"bounds":{"left":0.47473404,"top":0.09896249,"width":0.024268618,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"bounds":{"left":0.5013298,"top":0.09896249,"width":0.008643617,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"bounds":{"left":0.51230055,"top":0.09896249,"width":0.029587766,"height":0.01915403},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"bounds":{"left":0.7237367,"top":0.09896249,"width":0.02825798,"height":0.01915403},"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":"45","depth":4,"bounds":{"left":0.6938165,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.70611703,"top":0.123703115,"width":0.00731383,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"41","depth":4,"bounds":{"left":0.71542555,"top":0.123703115,"width":0.009640957,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXStaticText","text":"66","depth":4,"bounds":{"left":0.72706115,"top":0.123703115,"width":0.010305851,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.12210695,"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.7463431,"top":0.12210695,"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":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","depth":4,"on_screen":true,"value":"SELECT * FROM teams WHERE name LIKE '%litify%'; # 1069, 994, 24993\nSELECT * FROM users WHERE id = 25061;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 994;\nSELECT * FROM crm_profiles WHERE user_id = 25061;\n\nselect * from crm_configurations where id = 834;\nSELECT * FROM teams WHERE id = 882;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot' and crm_provider_id = 7270388;\n\nSELECT * FROM contacts where crm_configuration_id = 834;\nSELECT * FROM opportunities WHERE team_id = 933\n# AND crm_provider_id IN ('20131586060','46017317898','52543911090','53451356564','54101251892','54323768459');\nAND id IN (8482561,18352941,19042734,19232139,19445140,19472541);\nSELECT * FROM opportunity_contacts\nWHERE opportunity_id IN (8482561,18352941,19042734,19232139,19445140,19472541);\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 485; #\nSELECT * FROM opportunities WHERE team_id = 933 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\nselect crm.provider, l.* from leads l join crm_configurations crm on l.crm_configuration_id = crm.id\nwhere crm.provider NOT IN ('salesforce', 'integration-app', 'bullhorn', 'copper')\n# and l.converted_at IS NOT NULL\n;\n\n# ********************************************************************\nSELECT * FROM activities a WHERE type IN ('email-inbound', 'email-outbound')\nand opportunity_id IS NULL\norder by id desc;\n\nSELECT * FROM teams WHERE id = 604; # 598\nSELECT * FROM activities WHERE id = 74410828; # chelseaw@allvoices.co\nSELECT * FROM accounts WHERE id = 20068382;\nSELECT * FROM accounts WHERE id = 35186038;\n\nSELECT * FROM contacts WHERE team_id = 852 and updated_at > '2026-01-23 12:30:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 559 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('cb6342b6-a183-401c-b0af-ede92b2ae763') = uuid;\nselect * from sidekick_settings where team_id = 781;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 26651871; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 7562435;\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8420347; # opflit 2100\n\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 711;\nSELECT * FROM activities where crm_configuration_id = 711 and crm_provider_id IS NULL\nand is_internal = 0 and status = 'completed'\norder by id desc;\n\nSELECT * FROM crm_layout_entities\nWHERE crm_layout_id IN (2352, 2353);\n;\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and id = 530;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 556 and sa.provider = 'hubspot';\n\nSELECT * FROM activities WHERE uuid_to_bin('c6ca4b22-7738-4563-a95d-b8a9598924ae') = uuid;\nSELECT * FROM activities WHERE uuid_to_bin('442abb2b-28bd-4be8-9c25-19e9bf02766d') = uuid;\nselect * from contacts\nwhere crm_configuration_id = 530\nand crm_provider_id = 872252;\n\nselect * from activities where crm_configuration_id = 530\nand user_id = 14343 and type like '%softphone%'\nand created_at between '2026-01-28 15:00:00' and '2026-01-28 15:10:00';\n\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 25666868; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id = 8646335; # Teya\nSELECT * FROM crm_configurations where provider = 'hubspot' and crm_provider_id IN (5933397);\n\n\nSELECT t.name, t.id, t.owner_id, c.id, c.provider, c.crm_base_url FROM teams t\nJOIN crm_configurations c ON t.id = c.team_id\nWHERE t.status = 'active';\n\nSELECT * FROM teams where id = 1091;\nSELECT * FROM crm_configurations where team_id = 1091;\nSELECT * FROM activity_providers where team_id = 1091;\nSELECT * FROM activities where crm_configuration_id = 1024 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT * FROM teams WHERE name LIKE '%Leadventure%';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1091 and sa.provider = 'salesforce';\n\nSELECT * FROM teams WHERE name LIKE '%Wilson%'; # 862, 812\nSELECT * FROM teams where id = 862;\nSELECT * FROM crm_configurations where team_id = 862;\nSELECT * FROM activity_providers where team_id = 862;\nSELECT * FROM activities where crm_configuration_id = 812 and type IN ('softphone', 'softphone-outbound')\nand provider NOT IN ('hubspot', 'aircall')\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by id desc;\n\n\nSELECT t.id, crm.id, crm.provider, ap.* FROM teams t\njoin crm_configurations crm on t.id = crm.team_id\njoin activity_providers ap on t.id = ap.team_id\nwhere t.status = 'active' and ap.is_enabled = 1\nand crm.provider = 'hubspot'\nand ap.provider NOT IN ('hubspot', 'aircall', 'uploader', 'gong', 'twilio', 'zoom-bot', 'google-meet', 'ms-teams',\n 'outreach', 'close', 'ringcentral', 'dialpad', 'zoom-phone');\n\nSELECT * FROM teams where id = 1068;\nSELECT * FROM crm_configurations where team_id = 1068;\nSELECT * FROM activity_providers where team_id = 1068;\n\nSELECT * FROM activities a\nwhere crm_configuration_id = 993 and type IN ('softphone', 'softphone-outbound')\nand a.provider NOT IN ('hubspot', 'uploader', 'gong', 'twilio', 'google-meet', 'ms-teams','close'\n )\n# and telephony_provider_id = '019c1131-a22f-4792-b9ea-20adf6a02ed0'\norder by a.id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1068 and sa.provider = 'hubspot';\n\n# ********************************************************************\n# ********************************************************************\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 882; # 933 - GoGlobal , portalId: 6017093\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 933 and updated_at > '2026-02-06 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 933 and sa.provider = 'hubspot';\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 834; # 882 - AnyVan , portalId: 5468262\nSELECT * FROM contacts WHERE crm_configuration_id = 834 and updated_at > '2026-03-30 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and updated_at > '2026-03-04 08:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 882 and sa.provider = 'hubspot';\nselect * from crm_layouts where crm_configuration_id = 834;\nselect * from crm_layout_entities where crm_layout_id = 2780;\nselect * from crm_fields where id IN (321153,321192,321193,321194);\n\nSELECT * FROM opportunities WHERE crm_configuration_id = 834 and id = 10993426;\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 988; # 1057 - Teya (543ce4f4-168c-4571-91ea-5b35c253f06f) , portalId: 26651871\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1057 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1057 and sa.provider = 'hubspot';\n\nSELECT * FROM crm_configurations where id = 533; # 559 - Connectd , portalId: 6710988\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 559 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 801; # 852 - Rise Vision , portalId: 2700250\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 852 and updated_at > '2026-02-04 00:00:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 962; # 1034 - evergrowth.io , portalId: 143180990\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1034 and updated_at > '2026-02-04 00:00:00' order by updated_at desc;\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 1037; # 1102 - Jibble , portalId: 6649755\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1102 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 8\n\nSELECT * FROM crm_configurations where id = 1015; # 1049 - Travefy , portalId: 48904401\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1049 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 20\n\nSELECT * FROM crm_configurations where id = 64; # 70 - SalaryFinance , portalId: 3404115\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 70 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 6th last\n\nSELECT * FROM crm_configurations where id = 802; # 853 - Street Group , portalId: 7658438\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 853 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 10\n\nSELECT * FROM crm_configurations where id = 872; # 921 - In Professional Development , portalId: 9238273\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 921 and updated_at > '2026-02-04 12:30:00' order by updated_at desc; # 2\n\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 550; # 576 - SeedLegals , portalId: 3028661\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 576 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 989; # 1058 - rtaoutdoor.com , portalId: 22371204\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1058 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 896; # 946 - Mintago , portalId: 6621281\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 946 and updated_at > '2026-02-05 14:00:00' order by updated_at desc;\n\nSELECT * FROM crm_configurations where id = 617; # 641 - PCS , portalId: 5244937\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 641 and updated_at > '2026-02-05 14:00:00' order by updated_at desc; # 7th\n# ********************************************************************\nSELECT * FROM crm_configurations where id = 649; # 670 - Eventeny , portalId: 4492849\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-18 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 670 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; #\n\nSELECT * FROM crm_configurations where id = 48; # 51 - CleanCloud , portalId: 4373137\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-03-04 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 51 and updated_at > '2026-02-09 08:00:00' order by updated_at desc;\nselect * from users where team_id = 51; # 7783\nSELECT * FROM groups WHERE uuid_to_bin('8a8d2cb6-8b55-4fa3-8b5c-5f0e3d8de59a') = uuid; # 1130\nselect * from activity_searches where user_id = 7783;\nselect * from activity_search_filters where activity_search_id IN (32291, 32292);\n\nSELECT asf.activity_search_id, asf.id, asf.value\nFROM activity_search_filters asf\nWHERE asf.filter = 'group_id'\nAND asf.value IN (\n SELECT CONCAT(\n HEX(SUBSTR(uuid, 5, 4)), '-',\n HEX(SUBSTR(uuid, 3, 2)), '-',\n HEX(SUBSTR(uuid, 1, 2)), '-',\n HEX(SUBSTR(uuid, 9, 2)), '-',\n HEX(SUBSTR(uuid, 11))\n )\n FROM groups\n WHERE deleted_at IS NOT NULL\n);\n\nSELECT * FROM crm_configurations where id = 272; # 290 - Bonham & Brook , portalId: 5705856\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-05 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 290 and updated_at > '2026-02-09 08:00:00' order by updated_at desc; # 6th\n# ********************************************************************\nSELECT * FROM crm_configurations where provider = 'hubspot';\nSELECT * FROM crm_configurations where id = 1056; # 1119 - Chromatic , portalId: 45602133\nSELECT * FROM opportunities WHERE team_id = 1119 and remotely_created_at > '2026-02-01 00:00:00' order by updated_at desc;\nSELECT * FROM opportunities WHERE team_id = 1119 and updated_at > '2026-02-09 09:00:00' order by updated_at desc; # null\n# ********************************************************************\n\nselect * from contacts where crm_provider_id = '003Uu00000ojD4NIAU';\nselect\n cp.*\n# DISTINCT t.id\n# cp.id, cp.user_id, t.id, cp.crm_configuration_id, cp.contact_fields\nFROM crm_profiles cp\nJOIN crm_configurations crm on crm.id = cp.crm_configuration_id\nJOIN users u on u.id = cp.user_id\nJOIN teams t ON t.id = crm.team_id\nWHERE crm.provider = 'salesforce' and t.status = 'active'\n and cp.archived_at IS NULL and u.deleted_at IS NULL\n and t.id NOT IN (1093)\n and t.id = 2\n and cp.contact_fields IS NULL;\n# and c.crm_provider_id = '003Uu00000ojD4NIAU';\n\nSELECT * FROM users WHERE id = 26484;\nSELECT * FROM crm_profiles WHERE user_id = 26484;\nSELECT * FROM social_accounts WHERE sociable_id = 26484;\nSELECT * FROM crm_configurations where provider = 'salesforce';\nselect * from users where id IN (10022, 10403);\nselect * from users where team_id IN (526);\nselect * from teams where id IN (526, 532);\nselect * from crm_configurations where id IN (500, 516);\nselect * from crm_profiles where crm_configuration_id IN (500, 516) and user_id IN (10022, 10403);\nselect * from contacts where crm_configuration_id IN (500, 516) and crm_provider_id = '003Uu00000ojD4NIAU';\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 526 and sa.provider = 'salesforce';\nselect * from team_settings where team_id IN (526, 532);\n\nselect * from users where id IN (22824);\nselect * from crm_profiles where crm_configuration_id IN (1026);\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1093 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1099;\nselect * from users where id = 29643\n\nselect * from activity_processing_states;\n\nSELECT * FROM teams where name LIKE '%Fare%'; # 233\nSELECT * FROM opportunities where crm_configuration_id = 215\n# and crm_provider_id = 'oppo_ogESZf2P50nDrd1nGPvKDXeA6sSaTN5v51Lp4ayVzKR'\n;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1088 and sa.provider = 'hubspot';\n\nSELECT * FROM teams order by updated_at DESC\nSELECT * FROM crm_configurations WHERE id = 1019; # SimpleConsign 1088 - no social account\n\nselect * from crm_configurations where provider = 'pipedrive';\n\nselect * from teams where id = 957;\nselect * from crm_configurations where id = 957;\n\nSELECT * FROM teams WHERE name LIKE '%Prolific%'; # 544, 518, 10743\nSELECT * FROM opportunities where crm_configuration_id = 518 order by id desc;\n\nselect * from users where team_id = 1; # 26726 - Gabriela Dureva\nSELECT * FROM opportunities where user_id = 26726; # 16834447 - Prolific\nselect * from activities where user_id = 26726 order by id desc;\nselect * from contacts where crm_configuration_id = 1\nand email IN ('charlotte.ward@prolific.com', 'frankie.bryant@prolific.com'); # 2094416, 2093620\nSELECT * FROM contacts WHERE id = 6284931;\n\nSELECT p.* FROM activities a JOIN participants p ON a.id = p.activity_id\nWHERE a.user_id = 26726 and p.lead_id IN (2094416, 2093620) and a.created_at > '2026-01-01 00:00:00' order by p.email;\n\nselect * from activities where id IN (75509259,75509261,75509261,75511034,75026464,75517602,75517605);\nselect * from crm_configurations where id = 1;\n\n43801692-1aeb-32ce-acba-5b80a479701a\n44c3c9cf-6f5e-75f3-8179-bc9f75dd2b1b\n405975c0-b3d0-7aaa-821f-09d59cae6dd1\n4caf848d-4bed-2299-b248-7788d41f9fca\n49bedc3f-f196-eef3-89c3-dea6a3b4aa63\n43420989-a09d-b8f8-9806-c8bbf7a02aac\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nSELECT * FROM activities WHERE id = 75461988;\n\nSELECT * FROM activities WHERE uuid_to_bin('d6c5052e-e972-49e9-8912-26f2f7d6c5f6') = uuid;\n\nselect * from contacts where id = 17900517;\n\nselect * from contact_roles cr join crm_configurations crm on cr.crm_configuration_id = crm.id\nwhere crm.provider != 'salesforce';\n\nselect * from users where id = 21047;\nSELECT * FROM crm_configurations WHERE id = 892;\nSELECT * FROM teams WHERE id = 942;\nselect * from opportunities where team_id = 942 order by updated_at desc;\nselect * from contacts where team_id = 942 order by updated_at desc;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 942 and sa.provider = 'hubspot';\n\nSELECT * FROM opportunities where team_id = 1 and crm_provider_id IN ('006Pq00000NeH6XIAV', '006Pq000007z8kdIAA'); # 10697889, 6621430\nSELECT * FROM crm_configurations WHERE id = 1;\nSELECT * FROM teams WHERE crm_id = 1;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect id, user_id, opportunity_fields from crm_profiles where crm_configuration_id = 1\nSELECT * FROM opportunities where team_id = 1 order by updated_at desc; # 10697889, 6621430\n\nselect * from teams where id = 852;\nselect * from groups where id = 2286;\nselect * from sidekick_settings where team_id = 852;\nselect * from default_activity_types where team_id = 852;\n\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id AND p.id IS NULL -- no profile\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active' -- team is active\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1 AND u.deleted_at IS NULL\nAND u.crm_required = 1\nAND u.team_id = 1\nORDER BY u.team_id;\n\nSELECT * FROM crm_profiles cp where cp.crm_configuration_id = 1 and cp.user_id IN (\n18481\n );\n\nSELECT cc.provider, cc.id, p.id, u.*\nFROM users u\nLEFT JOIN crm_profiles p ON u.id = p.user_id\nINNER JOIN teams t ON u.team_id = t.id AND t.status = 'active'\nINNER JOIN crm_configurations cc ON t.crm_id = cc.id\nWHERE u.status = 1\n AND u.deleted_at IS NULL\n AND u.crm_required = 1\n# AND u.team_id = 1\n AND p.id IS NULL -- Move this condition to WHERE clause\nORDER BY u.team_id;\n\nSELECT * FROM opportunities WHERE id = 20002609;\nselect * from teams where id = 1122; # Velatir, 29953 - christian@velatir.com\nselect * from crm_configurations where id = 1060;\nselect * from crm_layouts where crm_configuration_id = 1060;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3596;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1122 and sa.provider = 'hubspot';\nselect * from opportunities where team_id = 1122 order by updated_at desc;\n\nselect * from crm_field_data where object_type = 'contact';\n\nSELECT * FROM activities WHERE uuid_to_bin('374fc8ed-3315-4c9f-9b25-318b7fd2928f') = uuid; # 76584262\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 248 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles where user_id = 24115; # 005QF000002CswMYAS\nSELECT * FROM users where id = 24115;\nSELECT * FROM accounts where id = 4002896;\nSELECT * FROM teams WHERE name LIKE '%adswerve%';\nSELECT * FROM opportunities where crm_configuration_id = 230 AND crm_provider_id IN (\"0069N000003GIQ9QAO\",\"0061r000019yGP9AAM\",\"0066900001S2KWlAAN\",\"0066900001TDpj2AAD\",\"0066900001b8uEwAAI\",\"0069N000001rQi0QAE\",\"006QF00000KD40mYAD\",\"006QF00000LzpRJYAZ\",\"0069N000002uomtQAA\",\"0069N000002xlMLQAY\",\"0066900001NV6ubAAD\",\"0061r00001HJp45AAD\",\"006QF00000uTlUoYAK\",\"006QF00000v0bZqYAI\");\nSELECT * FROM opportunities WHERE crm_configuration_id = 230 AND crm_provider_id = '0069N000003GIQ9QAO'; # 6272203\n\nSELECT u.id, u.email, ac.name, a.* FROM activities a\nJOIN users u ON a.user_id = u.id\nJOIN accounts ac ON a.account_id = ac.id\nWHERE\nuuid_to_bin('e3269598-b562-44fb-b5e9-9d2694dc63e0') = a.uuid or\nuuid_to_bin('66ddc3ab-4e15-45aa-af0c-248c1eece593') = a.uuid or\nuuid_to_bin('826bd328-e1cc-4213-b8d8-572454cacc07') = a.uuid;\n\nselect * from users where id = 5825;\nSELECT * FROM activities WHERE uuid_to_bin('e56aa2e8-231a-421b-ab1f-cb38ed2bf573') = uuid;\n\nselect * from activities where uuid_to_bin('91e13b2f-2d1b-45f8-b1fd-1141b6563782') = uuid;\n19594, 862\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 862 and sa.provider = 'salesforce';\n\nselect * from automated_reports where id = 36;\nselect ar.frequency, r.*, ar.* from automated_report_results r\njoin automated_reports ar on r.report_id = ar.id\nwhere ar.frequency != 'one_off';\n\nselect s.* from activity_searches s join users u ON s.user_id = u.id where u.team_id = 882;\nselect * from nudges n where n.activity_search_id\n\nselect * from teams where created_at > '2026-03-09';\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 1065; # 1065\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 3617;\n\nselect * from users where team_id = 1 and name like '%Lukas%'; # 7160\n\nSELECT * FROM teams WHERE id = 575;\nselect * from opportunities where team_id = 575;\nSELECT * FROM teams WHERE name LIKE '%Integrum ESG%'; # 1126, 1065,\nselect * from opportunities where team_id = 1126;\nSELECT * FROM teams WHERE name LIKE '%Base%'; # 1125, 1063,\nselect * from opportunities where team_id = 1125;\nselect * from contacts c\nwhere c.team_id = 882;\n\nSELECT * FROM activities WHERE id = 76822967;\nSELECT * FROM crm_profiles WHERE user_id = 15440;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 555;\nSELECT * FROM crm_configurations WHERE id = 555;\nSELECT * FROM users WHERE id = 15440; # team. 581, gr. 15440, pl. 3911, act. field 162182\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 581 and sa.provider = 'salesforce';\n\nSELECT * FROM automated_report_results order by id desc;\n\nselect * from features;\nselect * from team_features where feature_id = 40;\n\nselect * from teams where id = 556;\n\nselect * from automated_reports;\nwhere id = 54; # 4fdd41f6-dcf0-30d0-b339-7345381b6044 , [\"pdf\",\"podcast\"]\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\nselect * from automated_report_results order by id desc;\nSELECT * FROM automated_report_results WHERE id = 1919;\n\nselect * from automated_report_results WHERE report_id = 54;\n\nselect * from opportunities where id = 7594349;\n\nSELECT * FROM teams WHERE name LIKE '%Les%'; # 711, 692, 16067 - jiminnyintegration@lesmills.com\nselect * from playbooks where team_id = 711; # event 226147\nSELECT * FROM playbook_categories WHERE playbook_id = 5515;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 692 and object_type = 'event';\nSELECT * FROM crm_fields WHERE id = 226147;\nSELECT * FROM crm_field_values WHERE crm_field_id = 226147;\n\nSELECT * FROM crm_configurations WHERE id = 692;\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 711 and sa.provider = 'salesforce';\n\nSELECT * FROM crm_profiles cp JOIN users u on u.id = cp.user_id WHERE u.team_id = 711;\n\nselect * from leads;\n\nselect * from calendars;\n\nSELECT\n t.id AS team_id,\n t.name,\n LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1)) AS calendar_domain\nFROM teams t\nJOIN users u ON u.team_id = t.id\nJOIN calendars c ON c.user_id = u.id AND c.status = 'active' AND c.calendar_provider_id LIKE '%@%'\nLEFT JOIN team_domains td\n ON td.team_id = t.id\n AND td.deleted_at IS NULL\n AND td.domain = LOWER(SUBSTRING_INDEX(c.calendar_provider_id, '@', -1))\nGROUP BY t.id, t.name, calendar_domain\nORDER BY t.name, calendar_domain;\n\nselect * from users u join calendars c on c.user_id = u.id\nwhere u.team_id = 882;\n\n\nselect * from activities where id = 74049485; # team 563 crm 537\nselect * from activities where id = 73272382; # team 563 crm 537\nselect * from activities where id = 64400389; # team 563 crm 537\nselect * from activities where id = 58081273; # team 563 crm 537\nselect * from activities where id = 54520297; # team 563 crm 537\nselect * from participants where activity_id = 58081273;\n\nselect * from activities where crm_configuration_id = 537 and provider = 'aircall'\nand account_id = 19003658 order by updated_at desc;\n\nselect * from contacts where crm_configuration_id = 537 and id = 35957759;\nselect * from accounts where crm_configuration_id = 537 and id = 19003658;\n\nselect * from automated_report_results where id = 1976;\nselect * from automated_reports where id = 583;\nselect * from activity_searches where id = 87714;\nselect * from activity_search_filters where activity_search_id = 87714;\n\nSELECT * FROM activities WHERE uuid_to_bin('8827f672-202d-4162-9d04-73ff5f0566a9') = uuid\nor uuid_to_bin('47842446-af51-4bcb-854f-cc6560290101') = uuid;\n\nSELECT * FROM crm_configurations WHERE provider = 'hubspot';\nselect * from rate_limits;\n\nselect * from automated_report_results where media_type = 'pdf' and status = 2\nand id IN (18, 1872);\nselect * from automated_reports where id = 54;\nSELECT * FROM users WHERE id IN (24623,29443,29613);\n\nSELECT * FROM automated_report_results WHERE uuid_to_bin('822fa41b-afd3-43a9-a248-86b0e36f3131') = uuid;\n\nselect * from text_relays where created_at > '2026-05-01';\nand id IN (32415, 32416);\n# and id = 32412;\n\nselect * from users where team_id = 2 and email like '%scott%' and id = 29510;\n\nSELECT * FROM activities WHERE uuid_to_bin('67cebfc2-ed56-44a2-8c68-7a0286ed8618') = uuid; # 79763436\n\nSELECT email_provider_id, COUNT(*) as count, GROUP_CONCAT(id) as ids, GROUP_CONCAT(status) as statuses\nFROM text_relays\nWHERE email_provider_id IN ('19e2027868a64b42', '19e2033ed8ea6b10')\nGROUP BY email_provider_id;\nSELECT id, status, telephony_provider_id, created_at\nFROM activities\nWHERE id IN (80028719, 80028846);\nSELECT id, status, code, email_sent_at, created_at, updated_at\nFROM text_relays\nWHERE id IN (32415, 32416);\nSELECT id, status, code, sender, recipient, created_at\nFROM text_relays\nWHERE sender LIKE '%mario.georgiev%' OR sender LIKE '%stoyan.tomov%'\nORDER BY created_at DESC\nLIMIT 10;\n\nSELECT id, uuid, status, code, sender, recipient, created_at, updated_at\nFROM text_relays\nWHERE uuid = uuid_to_bin('0626141c-27a6-4d8c-aff8-7c8020a2c656');\n\n# ***************\nSELECT DISTINCT u.id, u.email, u.name, u.softphone_number, COUNT(a.id) as sms_count\nFROM users u\nINNER JOIN activities a ON u.id = .user_id\nWHERE a.type LIKE 'sms%'\nAND a.created_at > DATE_SUB(NOW(), INTERVAL 30 DAY)\nGROUP BY u.id, u.email, u.name, u.softphone_number\nORDER BY sms_count DESC;\n\nselect * from teams where id = 1;\n\nselect * from roles;\n\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1117 and sa.provider = 'hubspot';\nSELECT * FROM activities WHERE uuid_to_bin('8024fffb-2df7-4017-91f4-d9f896050248') = uuid; # 79933459 YES\nSELECT * FROM activities WHERE uuid_to_bin('25529043-8094-4781-927f-4f4da2a8185c') = uuid; # 80186192 NO\nSELECT * FROM crm_configurations WHERE id = 1053;\nSELECT * FROM teams WHERE id = 1117;\nselect * from users where id = 30249;\nselect * from playbooks where id = 5473;\nselect * from playbook_categories where id = 43783;\nselect * from playbook_categories where playbook_id = 5473;\nselect * from crm_fields where id = 659242;\nselect * from crm_field_values where crm_field_id = 659242;\n\nSELECT * FROM crm_field_data fd\n# JOIN crm_fields f ON fd.crm_field_id = f.id\n# JOIN activities a ON fd.activity_id = a.id\nWHERE activity_id = 79933459\n# AND f.crm_provider_id = 'hs_activity_type';\n\n\nSELECT * FROM activity_messages;\nselect * from text_relays where created_at > '2026-05-01';\nselect * from activities where user_id IN (7160, 18608) and created_at > '2026-05-22' order by id desc;\nselect * from users where team_id = 1 and id IN (18608, 13934, 7160);\nselect * from activities where user_id = 7160 order by id desc limit 10;\n\nselect * from accounts where team_id = 1 and name = 'Column5';\n\nselect * from users where name like '%Subra%'; # 31054, 1117\nselect * from teams where id = 1117;\nselect * from activity_searches where user_id = 31054;\nselect * from activity_search_filters where activity_search_id IN (88882, 88902);","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}]...
|
-5992080885439106011
|
-6520523836328617179
|
idle
|
accessibility
|
NULL
|
Pushed 1 commit to origin/JY-20963-fix-import-on-d Pushed 1 commit to origin/JY-20963-fix-import-on-deleted-entity
text/html
text/html
text/html
View pull request
1 file committed
JY-20963 add tests coverage
text/html
text/html
text/html
Edit Commit Message…
Project: faVsco.js, menu
#12121 on JY-20963-fix-import-on-deleted-entity, menu
Start Listening for PHP Debug Connections
ServiceTest
Run 'ServiceTest'
Debug 'ServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Built-in Preview
Chrome
Firefox
Safari
Sync Changes
Hide This Notification
Code changed:
Hide
3
32
81
1
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Tests\Unit\Services\Crm\Salesforce;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Facades\Cache;
use Jiminny\Component\Country\CountriesMap;
use Jiminny\Contracts\Repositories\TeamRepository;
use Jiminny\Enums\CrmObject;
use Jiminny\Exceptions\InvalidArgumentException;
use Jiminny\Exceptions\NoResultsException;
use Jiminny\Integrations\PlaybookResolver;
use Jiminny\Models\Activity;
use Jiminny\Models\Contact;
use Jiminny\Models\Crm\Configuration;
use Jiminny\Models\Crm\Profile;
use Jiminny\Models\Opportunity;
use Jiminny\Models\Playbook;
use Jiminny\Models\Team;
use Jiminny\Models\TeamSettings;
use Jiminny\Models\User;
use Jiminny\Repositories\Crm\ContactRoleRepository;
use Jiminny\Repositories\Crm\FieldDataRepository;
use Jiminny\Repositories\Crm\ProfileRepository;
use Jiminny\Services\Avatar\ProspectPhotoPathService;
use Jiminny\Services\Crm\Salesforce\Client;
use Jiminny\Services\Crm\Salesforce\PayloadBuilder;
use Jiminny\Services\Crm\Salesforce\QueryBuilder;
use Jiminny\Services\Crm\Salesforce\QueryHandler;
use Jiminny\Services\Crm\Salesforce\QueryIterator;
use Jiminny\Services\Crm\Salesforce\QueryResults;
use Jiminny\Services\Crm\Salesforce\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Tests\TestCase;
use Tests\Unit\Traits\TestPrivateMethod;
class ServiceTest extends TestCase
{
use TestPrivateMethod;
public function testFetchAndAssociateRelatedActivity(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$payloadBuilder->method('addCustomLogicFieldsPayload')
->willReturnCallback(function ($activity, $payload) {
return $payload;
});
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook', 'getPlaybookCategory', 'updateRecord'])
->getMock();
$serviceMock->expects($this->once())
->method('fetchRelatedActivity')
->willReturn([
'Id' => 'testId',
'Type' => null,
'OwnerId' => 'testerUser',
'Description' => 'Test description',
]);
$user = $this->createMock(User::class);
$team = $this->createMock(Team::class);
$user->method('getAttribute')->with('team')->willReturn($team);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityField')->willReturn(null);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_EVENT);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('getPlaybookCategory');
$serviceMock->expects($this->never())
->method('updateRecord');
$fieldDataRepository = $this->createMock(FieldDataRepository::class);
$fieldDataRepository->method('getActivityFieldData')->willReturn(collect([]));
app()->instance(FieldDataRepository::class, $fieldDataRepository);
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$config->method('profiles')->willReturn($profilesRelation);
$serviceMock->config = $config;
$serviceMock->profile = null;
$actualStartTime = \Carbon\Carbon::now();
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['update', 'hasProspect'])
->getMock();
$activity->method('update')->willReturn(true);
$activity->method('hasProspect')->willReturn(true);
$activity->type = Activity::TYPE_CONFERENCE;
$activity->provider = Activity::PROVIDER_TWILIO;
$activity->lead_id = 1;
$activity->user_id = 0;
$activity->id_string = 'test-activity-id';
$activity->user = $user;
$activity->actual_start_time = $actualStartTime;
$activity->uuid = 'c53d8320-f556-4cee-a2f8-5f232f454ca4';
app()->bind(PlaybookResolver::class, function () use ($user) {
$playbook = $this->createMock(Playbook::class);
$playbookResolver = $this->createMock(PlaybookResolver::class);
$playbookResolver->expects($this->once())
->method('resolvePlaybookByUser')
->with($user)
->willReturn($playbook);
return $playbookResolver;
});
$data = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertInstanceOf(Activity::class, $data);
$this->assertEquals(Activity::TYPE_CONFERENCE, $data->getType());
$this->assertEquals($actualStartTime->getTimestamp(), $data->getActualStartTime()->getTimestamp());
}
public function testFetchAndAssociateRelatedActivitySkipsForTaskBasedPlaybook(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['fetchRelatedActivity', 'getPlaybook'])
->getMock();
$user = $this->createMock(User::class);
$playbook = $this->createMock(Playbook::class);
$playbook->method('getActivityType')->willReturn(Playbook::ACTIVITY_TYPE_TASK);
$playbook->method('getId')->willReturn(123);
$serviceMock->expects($this->once())
->method('getPlaybook')
->with($user)
->willReturn($playbook);
$serviceMock->expects($this->never())
->method('fetchRelatedActivity');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(true);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$activity->user = $user;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullForNonConference(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_SOFTPHONE;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoStartTime(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$serviceMock = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->getMock();
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = null;
$activity->scheduled_start_time = null;
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testFetchAndAssociateRelatedActivityReturnsNullWhenNoProspect(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['getPlaybook'])
->getMock();
$serviceMock->expects($this->never())
->method('getPlaybook');
$activity = $this->getMockBuilder(Activity::class)
->disableOriginalConstructor()
->onlyMethods(['hasProspect', 'getUuid'])
->getMock();
$activity->method('hasProspect')->willReturn(false);
$activity->method('getUuid')->willReturn('c53d8320-f556-4cee-a2f8-5f232f454ca4');
$activity->type = Activity::TYPE_CONFERENCE;
$activity->actual_start_time = \Carbon\Carbon::now();
$result = $serviceMock->fetchAndAssociateRelatedActivity($activity);
$this->assertNull($result);
}
public function testMatchExactlyByEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods([])
->getMock();
$profile = new Profile();
$profile->setAttribute('id', bin2hex(random_bytes(8)));
$serviceMock->profile = $profile;
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$data = $serviceMock->matchExactlyByEmail(bin2hex(random_bytes(8)) . '[EMAIL]');
$this->assertEquals(null, $data);
}
public function testMatchDomainFromEmail(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$queryIterator = $this->createMock(QueryIterator::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$config = $this->createMock(Configuration::class);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('search')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(['convertCrmData'])
->getMock();
$profile = new Profile();
$profile->account_fields = 'Field1, Field2, Field3';
$serviceMock->profile = $profile;
$serviceMock->expects($this->once())
->method('convertCrmData')
->willReturn(['test']);
$this->app->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildMatchByDomainQuery')
->with('[EMAIL]')
->willReturn('FIND {[EMAIL]} IN ALL FIELDS RETURNING Account(Id)');
return $queryBuilder;
});
$team = $this->createMock(Team::class);
$serviceMock->team = $team;
$serviceMock->config = $config;
$data = $serviceMock->matchByDomain('[EMAIL]');
$this->assertEquals(['test'], $data);
}
public function testBuildTaskSearchFields(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class)
);
$fields = $service->buildTaskSearchFields();
$expectedFields = ['Id', 'WhoId', 'WhatId', 'AccountId'];
$this->assertEquals($expectedFields, $fields);
}
public function testMapCrmObjects(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$service = new Service(
client: $client,
payloadBuilder: $payloadBuilder,
eventDispatcher: $eventDispatcher,
countriesMap: $countriesMap,
prospectPhotoPathService: $this->createMock(ProspectPhotoPathService::class),
);
$sampleTask = [
'WhoId' => '003sampleWhoId',
'AccountId' => 'sampleAccountId',
'WhatId' => 'sampleWhatId',
];
$activityData = $service->mapCrmObjects($sampleTask);
$expectedActivityData = [
'contact' => '003sampleWhoId',
'account' => 'sampleAccountId',
'opportunity' => 'sampleWhatId',
];
$this->assertEquals($expectedActivityData, $activityData);
}
public function testGetInstalledAppVersion(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
$queryIterator = $this->createMock(QueryIterator::class);
$queryIterator->expects($this->any())
->method('current')->willReturn([
'SubscriberPackageVersion' => [
'MajorVersion' => '1',
'MinorVersion' => '0',
'PatchVersion' => '1',
'BuildNumber' => '0',
],
]);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('metadata')
->willReturn($queryIterator);
return $handler;
});
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods(array_diff(get_class_methods(Service::class), ['getInstalledAppVersion']))
->getMock();
$version = $serviceMock->getInstalledAppVersion();
$this->assertEquals('1010', $version);
}
public function testSyncProfiles(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testSyncProfilesEmailIsNull(): void
{
$userToSearch = $this->createMock(User::class);
$salesforceUser = [
'Email' => null,
];
app()->bind(QueryBuilder::class, function () {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with(null)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->exactly(2))
->method('query')
->willReturn($queryIterator);
return $handler;
});
$team = $this->createMock(Team::class);
$user = $this->createMock(User::class);
$this->mockTeamRepository($team, $salesforceUser, $user, false);
$config = $this->createMock(Configuration::class);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles(null);
$this->assertNull($profile);
}
public function testSyncProfilesUserToSearchMatchesCurrentUser(): void
{
$userToSearch = $this->createMock(User::class);
$userToSearch->expects($this->once())
->method('getId')
->willReturn(123);
$team = $this->createMock(Team::class);
$config = $this->createMock(Configuration::class);
$config->expects($this->once())
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
];
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults([$salesforceUser], 1, true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->with('SELECT * FROM Users')
->willReturn($queryIterator);
return $handler;
});
$user = $this->createMock(User::class);
$user->expects($this->exactly(2))
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user);
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertInstanceOf(Profile::class, $profile);
}
public function testSyncProfilesWithCustomValidation(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$config->expects($this->atLeastOnce()) // Changed from once() to atLeastOnce()
->method('getId')
->willReturn(1);
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'CustomValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$user = $this->createMock(User::class);
$user->expects($this->once())
->method('getId')
->willReturn(123);
$this->mockTeamRepository($team, $salesforceUser, $user, true, $customRules);
$this->mockProfileRepository($user);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$profile = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($profile);
}
public function testSyncProfilesWithCustomValidationFailing(): void
{
$userToSearch = null;
$team = $this->createMock(Team::class);
$config = $this->createMockedConfiguration();
$salesforceUser = [
'Email' => '[EMAIL]',
'UserPreferencesLightningExperiencePreferred' => true,
'CallCenterId' => '123',
'Id' => '456',
'ProfileId' => '789',
'CustomField' => 'WrongValue',
];
$customRules = [
['field' => 'CustomField', 'value' => 'CustomValue'],
];
$this->mockQueryBuilderAndHandler($userToSearch, [$salesforceUser]);
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->never())
->method('updateOrCreateProfile');
$this->app->instance(ProfileRepository::class, $profileRepository);
$serviceMock = $this->getServiceMock();
$serviceMock->team = $team;
$serviceMock->config = $config;
$result = $serviceMock->syncProfiles($userToSearch);
$this->assertNull($result);
}
public function testGetContactRolesFromCrm(): void
{
$contactRoles = [
[
'Id' => '1',
'ContactId' => 'Contact1',
'OpportunityId' => 'Opportunity1',
'Opportunity' => ['OwnerId' => 'Owner1'],
'IsPrimary' => true,
'Role' => 'Decision Maker',
],
];
$expectedResponse = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
$this->bindQueryIterator($contactRoles);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals($expectedResponse, $data);
}
public function testGetContactRolesFromCrmNoResult(): void
{
$this->bindQueryIterator([]);
$serviceMock = $this->getServiceMock();
$data = $serviceMock->getContactRolesFromCrm(now()->subDay());
$this->assertEquals([], $data);
}
public function testSyncContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'contactId' => 'Contact1',
'opportunityId' => 'Opportunity1',
'ownerId' => 'Owner1',
'isPrimary' => true,
'role' => 'Decision Maker',
],
];
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('saveContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock([
'getContactRolesFromCrm',
'syncRemotelyDeletedContactRoles',
'syncContact',
'syncOpportunity',
]);
$config = $this->createMock(Configuration::class);
$hasMany = $this->createMock(HasManyExtended::class);
$hasMany->expects($this->exactly(2))
->method('where')
->willReturn($hasMany);
$hasMany->expects($this->exactly(2))
->method('first')
->willReturn(
$this->createMock(Contact::class),
$this->createMock(Opportunity::class)
);
$config->expects($this->once())
->method('contacts')
->willReturn($hasMany);
$config->expects($this->once())
->method('opportunities')
->willReturn($hasMany);
$serviceMock->config = $config;
$serviceMock->expects($this->once())
->method('getContactRolesFromCrm')
->willReturn($contactRoles);
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedContactRoles');
$data = $serviceMock->syncContactRoles(now()->subDay());
$this->assertEquals(1, $data);
}
public function testSyncRemotelyDeletedContactRoles(): void
{
$contactRoles = [
[
'id' => '1',
'crm_provider_id' => '1',
],
];
app()->bind(QueryHandler::class, function () use ($contactRoles) {
$queryResults = new QueryResults($contactRoles, 1, true, null);
$handler = $this->createMock(QueryHandler::class);
$handler->method('queryDeleted')
->willReturn($queryResults);
return $handler;
});
app()->bind(ContactRoleRepository::class, function () {
$contactRoleRepository = $this->createMock(ContactRoleRepository::class);
$contactRoleRepository->expects($this->once())
->method('deleteContactRoles');
return $contactRoleRepository;
});
$serviceMock = $this->getServiceMock();
$serviceMock->team = $this->createMock(Team::class);
$data = $this->invokePrivateMethod('syncRemotelyDeletedContactRoles', $serviceMock, []);
$this->assertTrue($data);
}
private function bindQueryIterator(array $queryResult): void
{
/** @var Client $client */
$client = $this->createMock(Client::class);
$queryIterator = new QueryIterator(
$client,
new QueryResults($queryResult, 1, true, null)
);
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
public static function getOpportunitySortOrderDataProvider(): array
{
return [
'all open recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_UPDATED, ['LastModifiedDate DESC', true]],
'all open recently created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_RECENTLY_CREATED, ['CreatedDate DESC', true]],
'all open oldest created' => [Configuration::OPP_ASSIGNMENT_ALL_OPEN_OLDEST_CREATED, ['CreatedDate ASC', true]],
'all recently updated' => [Configuration::OPP_ASSIGNMENT_ALL_RECENTLY_UPDATED, ['LastModifiedDate DESC', false]],
'default' => ['unknown', ['LastModifiedDate DESC', true]],
];
}
private function createMockedConfiguration(): Configuration
{
$config = $this->createMock(Configuration::class);
$profilesRelation = $this->getMockBuilder(\Illuminate\Database\Eloquent\Relations\HasMany::class)
->disableOriginalConstructor()
->onlyMethods(['get'])
->addMethods(['where', 'first'])
->getMock();
$profilesRelation->method('where')->willReturnSelf();
$profilesRelation->method('get')->willReturn(collect([]));
$profilesRelation->method('first')->willReturn(null);
$config->method('profiles')->willReturn($profilesRelation);
return $config;
}
private function getServiceMock(array $onlyMethods = []): MockObject&Service
{
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$this->createMock(Client::class),
$this->createMock(PayloadBuilder::class),
$this->createMock(Dispatcher::class),
$this->createMock(CountriesMap::class),
$this->createMock(ProspectPhotoPathService::class),
])
->onlyMethods($onlyMethods)
->getMock();
$serviceMock->profile = $this->createMock(Profile::class);
return $serviceMock;
}
private function mockQueryBuilderAndHandler($userToSearch, $salesforceUsers): void
{
app()->bind(QueryBuilder::class, function () use ($userToSearch) {
$queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->expects($this->once())
->method('buildGetUsersQuery')
->with($userToSearch)
->willReturn('SELECT * FROM Users');
return $queryBuilder;
});
$queryIterator = new QueryIterator($this->createMock(Client::class), new QueryResults($salesforceUsers, count($salesforceUsers), true, null));
app()->bind(QueryHandler::class, function () use ($queryIterator) {
$handler = $this->createMock(QueryHandler::class);
$handler->expects($this->any())
->method('query')
->willReturn($queryIterator);
return $handler;
});
}
private function mockTeamRepository(
Team $team,
array $salesforceUser,
?User $user = null,
bool $userSearch = true,
array $customRules = []
): void {
$teamRepository = $this->getMockForAbstractClass(TeamRepository::class, [], '', false, true, true, ['findActiveTeamMemberByEmail', 'getTeamSetting']);
if ($userSearch) {
$teamRepository->expects($this->once())
->method('findActiveTeamMemberByEmail')
->with($team, $salesforceUser['Email'])
->willReturn($user);
}
$teamSettings = $this->createMock(TeamSettings::class);
$teamSettings->method('getValueType')
->willReturn('array');
$teamSettings->method('getValue')
->willReturn(json_encode($customRules));
$teamRepository->expects($this->once())
->method('getTeamSetting')
->with($team, 'custom_profile_validation')
->willReturn($teamSettings);
app()->bind(TeamRepository::class, function () use ($teamRepository) {
return $teamRepository;
});
}
private function mockProfileRepository(User $user): void
{
$profileRepository = $this->createMock(ProfileRepository::class);
$profileRepository->expects($this->once())
->method('updateOrCreateProfile')
->with(
$user,
[
'crm_configuration_id' => 1,
'crm_provider_id' => '456',
],
[
'user_id' => 123,
'edition' => Profile::EDITION_LIGHTNING,
'has_external_cti' => true,
'crm_profile_id' => '789',
]
)
->willReturn(new Profile());
$this->app->instance(ProfileRepository::class, $profileRepository);
}
public function testBuildEnhancedNoteDecodesHtmlEntities(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-123');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnOnConsecutiveCalls('note-id-123', 'link-id-456');
$bodyWithEntities = 'Welch's current challenges and Facebook's Club';
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithEntities,
'object-id-789',
]);
$this->assertEquals('note-id-123', $result);
}
public function testBuildEnhancedNoteSanitizesWithoutQuotes(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-456');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<script>', $decoded);
return 'note-id-456';
}
return 'link-id-789';
});
$bodyWithMixedContent = "Welch's and <script>alert('xss')</script>";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithMixedContent,
'object-id-123',
]);
$this->assertEquals('note-id-456', $result);
}
public function testBuildEnhancedNoteConvertsLineBreaks(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-789');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringNotContainsString('<br />', $decoded);
return 'note-id-789';
}
return 'link-id-012';
});
$bodyWithLineBreaks = "Line 1\nLine 2\nLine 3";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Test Title',
$bodyWithLineBreaks,
'object-id-456',
]);
$this->assertEquals('note-id-789', $result);
}
public function testBuildEnhancedNoteHandlesComplexScenario(): void
{
$service = $this->getServiceMock(['createRecord']);
$profile = new Profile();
$profile->setAttribute('crm_provider_id', 'owner-complex');
$service->profile = $profile;
$service->expects($this->exactly(2))
->method('createRecord')
->willReturnCallback(function ($type, $data) {
if ($type === 'ContentNote') {
$decoded = base64_decode($data['Content']);
$this->assertStringContainsString("Welch's", $decoded);
$this->assertStringContainsString("Facebook's Club", $decoded);
$this->assertStringContainsString("Arctics'", $decoded);
$this->assertStringNotContainsString(''', $decoded);
$this->assertStringNotContainsString('&#039;', $decoded);
$this->assertStringContainsString('<br>', $decoded);
$this->assertStringContainsString('<', $decoded);
$this->assertStringContainsString('>', $decoded);
return 'note-complex';
}
return 'link-complex';
});
$complexBody = "Summary:\n---------\nThe call focused on understanding Welch's current challenges and exploring how Arctics' Revenue Growth Management solutions could support their strategic goals.\n\n• John SMith discussed his role as a category advisor for Google and Facebook's Club, emphasizing the importance of market research and advising on product assortment.\n• Madona introduced Arctics' Virtual Shoppers AI, which simulates consumer <behavior> to optimize pricing and promotional strategies.";
$result = $this->invokePrivateMethod('buildEnhancedNote', $service, [
'Jiminny Transcription Summary',
$complexBody,
'task-id-001',
]);
$this->assertEquals('note-complex', $result);
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingSuccess(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-123');
$serviceMock->team = $team;
// Expect syncRemotelyDeletedObjects to be called once and succeed
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::ACCOUNT);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not throw any exceptions
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::ACCOUNT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingFailure(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-456');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$reflection = new \ReflectionClass($serviceMock);
$loggerProperty = $reflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Sync failed due to API error');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::CONTACT)
->willThrowException($exception);
// Expect warning to be logged with correct message and parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'contact',
'teamId' => 'team-uuid-456',
'reason' => 'Sync failed due to API error',
]
);
// Call the protected method using reflection
$reflection = new \ReflectionClass($serviceMock);
$method = $reflection->getMethod('syncRemotelyDeletedObjectsWithErrorHandling');
$method->setAccessible(true);
// Should not re-throw the exception, just log it
$method->invoke($serviceMock, \Jiminny\Enums\CrmObject::CONTACT);
$this->assertTrue(true); // Test completed successfully
}
public function testSyncRemotelyDeletedObjectsWithErrorHandlingWithLogParams(): void
{
$client = $this->createMock(Client::class);
$payloadBuilder = $this->createMock(PayloadBuilder::class);
$countriesMap = $this->createMock(CountriesMap::class);
$prospectPhotoPathService = $this->createMock(ProspectPhotoPathService::class);
$eventDispatcher = $this->createMock(Dispatcher::class);
/** @var Service&MockObject $serviceMock */
$serviceMock = $this->getMockBuilder(Service::class)
->setConstructorArgs([
$client,
$payloadBuilder,
$eventDispatcher,
$countriesMap,
$prospectPhotoPathService,
])
->onlyMethods(['syncRemotelyDeletedObjects'])
->getMock();
// Mock team
$team = $this->createMock(Team::class);
$team->method('getUuid')->willReturn('team-uuid-789');
$serviceMock->team = $team;
// Mock logger to verify warning is logged
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
// Use reflection to set the protected logger property
$loggerReflection = new \ReflectionClass($serviceMock);
$loggerProperty = $loggerReflection->getProperty('logger');
$loggerProperty->setAccessible(true);
$loggerProperty->setValue($serviceMock, $logger);
$exception = new \Exception('Network timeout');
// Expect syncRemotelyDeletedObjects to throw an exception
$serviceMock->expects($this->once())
->method('syncRemotelyDeletedObjects')
->with(\Jiminny\Enums\CrmObject::OPPORTUNITY)
->willThrowException($exception);
// Additional log parameters
$logParams = [
'syncType' => 'full',
'batchSize' => 100,
];
// Expect warning to be logged with merged parameters
$logger->expects($this->once())
->method('warning')
->with(
'[Salesforce] Remotely deleted objects sync failed',
[
'objectType' => 'opportunity',
'teamId' => 'team-uuid-789',
'reason' => 'Network timeout',
'syncType' => 'full',
'batchSize' => 100,
]
);
// Call the pr...
|
85812
|
NULL
|
NULL
|
NULL
|