Skip to content

Conversation

@capcom6
Copy link
Member

@capcom6 capcom6 commented Sep 14, 2025

Summary by CodeRabbit

  • New Features

    • Introduced message priority levels (Minimum, Default, Bypass Threshold, Maximum).
    • Messages now support an optional priority field; when set, it appears in serialized output as an integer and fields with no value are omitted.
  • Tests

    • Added parametrized tests validating serialization: camelCase keys, omission of None fields, and integer priority representation.
  • Chores

    • Added workspace test runner configuration for consistent local testing.

Copy link

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
android_sms_gateway/domain.py (1)

22-29: Unwrap Enum values in Message.asdict for consistency with Webhook.asdict.

Currently priority (IntEnum) lands in the dict as an IntEnum instance (JSON encodes fine), but unwrapping Enums to their .value keeps asdict behavior consistent across models and avoids surprises for non-JSON consumers.

Apply this diff to asdict (and import enum):

+import enum
@@
     def asdict(self) -> t.Dict[str, t.Any]:
-        return {
-            snake_to_camel(field.name): getattr(self, field.name)
-            for field in dataclasses.fields(self)
-            if getattr(self, field.name) is not None
-        }
+        result: t.Dict[str, t.Any] = {}
+        for field in dataclasses.fields(self):
+            value = getattr(self, field.name)
+            if value is None:
+                continue
+            if isinstance(value, enum.Enum):
+                value = value.value
+            result[snake_to_camel(field.name)] = value
+        return result
🧹 Nitpick comments (3)
android_sms_gateway/enums.py (1)

33-39: Add brief member-level docs for semantics (e.g., scheduling/queue behavior).

Helps consumers understand MINIMUM/DEFAULT/BYPASS_THRESHOLD/MAXIMUM effects on server-side handling.

android_sms_gateway/domain.py (1)

22-22: Optionally coerce raw ints to MessagePriority in post_init.

Guards callers passing plain ints and provides a clear error on invalid ranges while keeping the dataclass frozen.

Add this to Message:

def __post_init__(self):
    if isinstance(self.priority, int) and not isinstance(self.priority, MessagePriority):
        try:
            object.__setattr__(self, "priority", MessagePriority(self.priority))
        except ValueError as e:
            raise ValueError("priority must be a valid MessagePriority") from e
tests/test_domain.py (1)

140-226: Add edge-case cases for DEFAULT and MINIMUM priorities.

Covers 0 and negative bounds to lock in serialization behavior.

Append to the param list:

@@
         ),
+        (
+            "Hello, world!",
+            ["123", "456"],
+            True,
+            False,
+            "msg_123",
+            None,
+            None,
+            MessagePriority.DEFAULT,
+            {
+                "message": "Hello, world!",
+                "phoneNumbers": ["123", "456"],
+                "withDeliveryReport": True,
+                "isEncrypted": False,
+                "id": "msg_123",
+                "priority": 0,
+            },
+        ),
+        (
+            "Hi",
+            ["555"],
+            True,
+            False,
+            None,
+            None,
+            None,
+            MessagePriority.MINIMUM,
+            {
+                "message": "Hi",
+                "phoneNumbers": ["555"],
+                "withDeliveryReport": True,
+                "isEncrypted": False,
+                "priority": -128,
+            },
+        ),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4bcb3a and 360d9a5.

📒 Files selected for processing (3)
  • android_sms_gateway/domain.py (2 hunks)
  • android_sms_gateway/enums.py (1 hunks)
  • tests/test_domain.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/test_domain.py (2)
android_sms_gateway/enums.py (1)
  • MessagePriority (33-39)
android_sms_gateway/domain.py (3)
  • Message (13-29)
  • asdict (24-29)
  • asdict (96-106)
android_sms_gateway/domain.py (1)
android_sms_gateway/enums.py (1)
  • MessagePriority (33-39)
🔇 Additional comments (3)
android_sms_gateway/enums.py (1)

33-39: LGTM: MessagePriority is well-scoped and uses IntEnum appropriately.

Clear range and sensible defaults. No blocking issues.

android_sms_gateway/domain.py (1)

4-4: LGTM: Import of MessagePriority is correct and localized.

tests/test_domain.py (1)

3-4: LGTM: Imports reflect new public API surface.

@coderabbitai
Copy link

coderabbitai bot commented Sep 14, 2025

Walkthrough

Adds a new MessagePriority IntEnum and an optional priority field to the Message dataclass; Message.asdict now omits None fields and serializes priority as an integer when present. Tests were added to validate serialization; a VS Code test setting file was also added.

Changes

Cohort / File(s) Summary of Changes
Enums: MessagePriority
android_sms_gateway/enums.py
Added public IntEnum MessagePriority with members MINIMUM = -128, DEFAULT = 0, BYPASS_THRESHOLD = 100, MAXIMUM = 127 and a class docstring (per-member docstrings added).
Domain: Message dataclass
android_sms_gateway/domain.py
Imported MessagePriority; added optional field priority: Optional[MessagePriority] = None; updated asdict to include only non-None fields (serializes priority as an int); added/expanded docstrings.
Tests: domain serialization
tests/test_domain.py
Added parametrized test_message_asdict covering camelCase keys, omission of None fields, and integer representation of priority; imports Message and MessagePriority.
Editor config: VS Code
.vscode/settings.json
Added workspace settings enabling pytest with pytestArgs: ["tests"].

Sequence Diagram(s)

N/A

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "[client] add priority support" is concise, a single short sentence, and accurately summarizes the main change—adding priority support to the client (which aligns with the new MessagePriority enum, the priority field on Message, and updated tests). It is specific and clear enough for a reviewer or teammate to understand the primary intent of the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch client/priority-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@capcom6 capcom6 force-pushed the client/priority-support branch from 9056d61 to bb7d18b Compare September 15, 2025 06:16
Copy link

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
android_sms_gateway/domain.py (1)

38-49: Serialize enums to primitives in asdict (priority currently emitted as Enum).

asdict returns the Enum object for priority; emit its primitive value for consistency (similar to Webhook.event.value) and to avoid downstream surprises.

Apply this change to asdict:

 def asdict(self) -> t.Dict[str, t.Any]:
-        """
-        Returns a dictionary representation of the message.
-
-        Returns:
-            Dict[str, Any]: A dictionary representation of the message.
-        """
-        return {
-            snake_to_camel(field.name): getattr(self, field.name)
-            for field in dataclasses.fields(self)
-            if getattr(self, field.name) is not None
-        }
+        """
+        Returns a dictionary representation of the message.
+        Enum fields are serialized to their underlying values.
+
+        Returns:
+            Dict[str, Any]: A dictionary representation of the message.
+        """
+        result: t.Dict[str, t.Any] = {}
+        for field in dataclasses.fields(self):
+            value = getattr(self, field.name)
+            if value is None:
+                continue
+            # IntEnum (and Enum) -> primitive for JSON friendliness
+            if hasattr(value, "value"):
+                try:
+                    value = value.value  # Enum/IntEnum
+                except Exception:
+                    pass
+            result[snake_to_camel(field.name)] = value
+        return result

If you prefer a stricter type check, import enum and use isinstance(value, enum.Enum).

🧹 Nitpick comments (1)
android_sms_gateway/domain.py (1)

14-26: Docstring LGTM; tiny clarity nit.

Consider noting the valid numeric range for priority (-128..127) to match MessagePriority.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 360d9a5 and bb7d18b.

📒 Files selected for processing (4)
  • .vscode/settings.json (1 hunks)
  • android_sms_gateway/domain.py (3 hunks)
  • android_sms_gateway/enums.py (1 hunks)
  • tests/test_domain.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_domain.py
  • android_sms_gateway/enums.py
🧰 Additional context used
🧬 Code graph analysis (1)
android_sms_gateway/domain.py (1)
android_sms_gateway/enums.py (1)
  • MessagePriority (33-46)
🔇 Additional comments (2)
android_sms_gateway/domain.py (2)

4-4: Import looks good.

MessagePriority is used by the new field; import is correct.


36-36: Optional priority field is backward‑compatible.

Because None fields are omitted in asdict, older servers won’t see the key unless set. Good design.

Please confirm the upstream API expects the camelCase key "priority" with an integer value.

@capcom6 capcom6 merged commit f32953f into master Sep 17, 2025
9 checks passed
@capcom6 capcom6 deleted the client/priority-support branch September 17, 2025 12:10
@coderabbitai coderabbitai bot mentioned this pull request Oct 12, 2025
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