Skip to content

MPT-18370 Add helpdesk queues API services with unit and e2e test coverage#243

Merged
jentyk merged 1 commit intomainfrom
feat/MPT-18370
Mar 23, 2026
Merged

MPT-18370 Add helpdesk queues API services with unit and e2e test coverage#243
jentyk merged 1 commit intomainfrom
feat/MPT-18370

Conversation

@jentyk
Copy link
Copy Markdown
Member

@jentyk jentyk commented Mar 23, 2026

Summary

  • Add Queue resource with sync and async QueuesService implementations under Helpdesk
  • Implement queue state transition actions: activate and disable
  • Wire queues accessors into sync and async Helpdesk module entrypoints
  • Add unit tests for service availability and custom action request/response behavior
  • Add Helpdesk e2e queue test scaffolding (sync/async) aligned with existing skipped Helpdesk e2e style

Testing

  • uv run pytest tests/unit/resources/helpdesk/test_queues.py tests/unit/resources/helpdesk/test_helpdesk.py
  • make check-all
  • e2e tests: Not run (not requested)

Closes MPT-18370

Changes

  • Added Queue model and QueuesService (synchronous) and AsyncQueuesService (asynchronous) implementations under the Helpdesk module
  • Configured queue API endpoint (/public/v1/helpdesk/queues) with collection key data
  • Implemented queue state transition actions: activate() and disable() methods for both sync and async services, supporting optional resource data payload
  • Added queues property accessors to both Helpdesk and AsyncHelpdesk entry points for accessing the queue services
  • Added comprehensive unit tests covering service availability, custom action request/response behavior, and expected public methods
  • Added end-to-end test scaffolding for queue operations (sync/async variants) including CRUD operations, listing with pagination, state transitions, and error handling; most tests marked as skipped pending MPT-19124 completion, with only the not-found error handling test active

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 6c8bbbd8-180d-48fc-a4b3-66f74bdef63b

📥 Commits

Reviewing files that changed from the base of the PR and between 8ca1390 and cb00019.

📒 Files selected for processing (7)
  • mpt_api_client/resources/helpdesk/helpdesk.py
  • mpt_api_client/resources/helpdesk/queues.py
  • tests/e2e/helpdesk/queues/conftest.py
  • tests/e2e/helpdesk/queues/test_async_queues.py
  • tests/e2e/helpdesk/queues/test_sync_queues.py
  • tests/unit/resources/helpdesk/test_helpdesk.py
  • tests/unit/resources/helpdesk/test_queues.py
✅ Files skipped from review due to trivial changes (2)
  • tests/unit/resources/helpdesk/test_helpdesk.py
  • mpt_api_client/resources/helpdesk/queues.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • mpt_api_client/resources/helpdesk/helpdesk.py
  • tests/unit/resources/helpdesk/test_queues.py
  • tests/e2e/helpdesk/queues/test_sync_queues.py

📝 Walkthrough

Walkthrough

This PR introduces a new Helpdesk Queues resource to the API client, adding a Queue model with service classes that provide CRUD operations and custom state-transition actions (activate/disable). The queues service is integrated into the Helpdesk and AsyncHelpdesk classes via new properties, with comprehensive unit and E2E test coverage.

Changes

Cohort / File(s) Summary
Service Implementation
mpt_api_client/resources/helpdesk/helpdesk.py, mpt_api_client/resources/helpdesk/queues.py
Added Queue model and QueuesService/AsyncQueuesService classes with activate() and disable() state-transition operations. Integrated queues service into Helpdesk and AsyncHelpdesk via property accessors.
Unit Tests
tests/unit/resources/helpdesk/test_helpdesk.py, tests/unit/resources/helpdesk/test_queues.py
Added parametrized unit tests verifying service instantiation and public method availability; included mocked HTTP POST tests for activate/disable actions.
E2E Tests
tests/e2e/helpdesk/queues/conftest.py, tests/e2e/helpdesk/queues/test_sync_queues.py, tests/e2e/helpdesk/queues/test_async_queues.py
Added fixture definitions for queue test data and lifecycle management, plus comprehensive sync/async E2E tests for get, list, create, update, delete, activate, and disable operations; most tests skipped pending MPT-19124 completion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed PR title contains exactly one Jira issue key (MPT-18370) in the correct MPT-XXXX format.
Test Coverage Required ✅ Passed PR modifies 2 code files and includes comprehensive test coverage with 5 test files added or modified across unit and end-to-end tests.
Single Commit Required ✅ Passed The PR contains exactly one commit that introduces all changes for helpdesk queues API services, maintaining clean git history.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@jentyk jentyk changed the title Add helpdesk queues API services with unit and e2e test coverage MPT-18370 Add helpdesk queues API services with unit and e2e test coverage Mar 23, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/resources/helpdesk/test_queues.py (2)

44-64: Add sync “with payload” action tests for parity with async coverage.

Right now only async actions assert request-body propagation; adding the same assertion path for sync actions will make regression detection stronger for both service variants.

💡 Suggested additional test
+@pytest.mark.parametrize(
+    ("action", "input_data"),
+    [
+        ("activate", {"id": "HQU-1234-5678", "status": "Active"}),
+        ("disable", {"id": "HQU-1234-5678", "status": "Disabled"}),
+    ],
+)
+def test_custom_resource_actions_with_data(queues_service, action, input_data):
+    response_expected_data = {"id": "HQU-1234-5678", "status": "Updated"}
+    with respx.mock:
+        mock_route = respx.post(
+            f"https://api.example.com/public/v1/helpdesk/queues/HQU-1234-5678/{action}"
+        ).mock(
+            return_value=httpx.Response(
+                status_code=httpx.codes.OK,
+                headers={"content-type": "application/json"},
+                json=response_expected_data,
+            )
+        )
+
+        result = getattr(queues_service, action)("HQU-1234-5678", input_data)
+
+        assert mock_route.call_count == 1
+        request = mock_route.calls[0].request
+        assert request.content == b'{"id":"HQU-1234-5678","status":"Active"}' if action == "activate" else b'{"id":"HQU-1234-5678","status":"Disabled"}'
+        assert result.to_dict() == response_expected_data
+        assert isinstance(result, Queue)

Also applies to: 67-95

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/helpdesk/test_queues.py` around lines 44 - 64, The sync
tests (test_custom_resource_actions_no_data /
tests/unit/resources/helpdesk/test_queues.py) only cover no-body calls; add
matching "with payload" sync tests that mirror the async coverage by calling
getattr(queues_service, action) with a payload dict, mocking the POST to the
same URL and asserting mock_route.call_count == 1, that request.content equals
the JSON-encoded payload bytes (not b""), and that the returned result.to_dict()
matches the mocked response and is an instance of Queue; repeat for both actions
("activate", "disable") to achieve parity with the existing async payload
assertions.

8-11: Avoid brittle raw-byte JSON assertions in async payload checks.

Comparing request.content to hardcoded bytes can fail on semantically equivalent serialization differences (key order/encoding). Prefer asserting parsed JSON content.

💡 Suggested change
+import json
 ...
-def _request_content(action: str) -> bytes:
-    if action == "activate":
-        return b'{"id":"HQU-1234-5678","status":"Active"}'
-    return b'{"id":"HQU-1234-5678","status":"Disabled"}'
-
 ...
-    request_expected_content = _request_content(action)
 ...
-        assert request.content == request_expected_content
+        assert json.loads(request.content.decode()) == input_data

Also applies to: 75-76, 91-93

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/helpdesk/test_queues.py` around lines 8 - 11, The tests
use brittle byte-string equality by comparing request.content to hardcoded bytes
in the helper _request_content and in the test assertions; replace those
raw-byte comparisons with JSON parsing and structural assertions: decode/parse
request.content using json.loads (or json.loads(request.content.decode())) and
compare dictionaries or specific fields (e.g., ["id"], ["status"]) instead of
exact byte sequences; update the helper _request_content usages and the two
other assertions that compare request.content so they assert on parsed JSON
objects or keys rather than hardcoded bytes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/e2e/helpdesk/queues/conftest.py`:
- Around line 17-22: The teardown in the created_queue fixture currently calls
mpt_ops.helpdesk.queues.delete(queue.id) unconditionally which can double-delete
if the test already removed the queue; change the teardown to be best-effort by
wrapping the delete in a try/except that catches and swallows not-found/HTTP
errors (or check existence via mpt_ops.helpdesk.queues.get before deleting) so
teardown never raises on already-deleted resources; apply the same pattern to
the other fixture(s) that call mpt_ops.helpdesk.queues.delete in teardown.

---

Nitpick comments:
In `@tests/unit/resources/helpdesk/test_queues.py`:
- Around line 44-64: The sync tests (test_custom_resource_actions_no_data /
tests/unit/resources/helpdesk/test_queues.py) only cover no-body calls; add
matching "with payload" sync tests that mirror the async coverage by calling
getattr(queues_service, action) with a payload dict, mocking the POST to the
same URL and asserting mock_route.call_count == 1, that request.content equals
the JSON-encoded payload bytes (not b""), and that the returned result.to_dict()
matches the mocked response and is an instance of Queue; repeat for both actions
("activate", "disable") to achieve parity with the existing async payload
assertions.
- Around line 8-11: The tests use brittle byte-string equality by comparing
request.content to hardcoded bytes in the helper _request_content and in the
test assertions; replace those raw-byte comparisons with JSON parsing and
structural assertions: decode/parse request.content using json.loads (or
json.loads(request.content.decode())) and compare dictionaries or specific
fields (e.g., ["id"], ["status"]) instead of exact byte sequences; update the
helper _request_content usages and the two other assertions that compare
request.content so they assert on parsed JSON objects or keys rather than
hardcoded bytes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: e599e889-9fec-4196-a025-e261cf60733f

📥 Commits

Reviewing files that changed from the base of the PR and between 1956bc6 and 8ca1390.

📒 Files selected for processing (7)
  • mpt_api_client/resources/helpdesk/helpdesk.py
  • mpt_api_client/resources/helpdesk/queues.py
  • tests/e2e/helpdesk/queues/conftest.py
  • tests/e2e/helpdesk/queues/test_async_queues.py
  • tests/e2e/helpdesk/queues/test_sync_queues.py
  • tests/unit/resources/helpdesk/test_helpdesk.py
  • tests/unit/resources/helpdesk/test_queues.py

@sonarqubecloud
Copy link
Copy Markdown

@jentyk jentyk marked this pull request as ready for review March 23, 2026 10:40
@jentyk jentyk requested a review from a team as a code owner March 23, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants