Skip to content

Conversation

gaalferov
Copy link
Collaborator

@gaalferov gaalferov commented Sep 18, 2025

Motivation

Support new create contact event functionality

Changes

  • Add CreateContactEvent functionality and related tests

How to test

composer test

Summary by CodeRabbit

  • New Features

    • Added ability to create contact events via the API (identify contacts by email or ID).
  • Documentation

    • Updated README to list new capabilities: Sending domain management (CRUD), Import events, and Billing info.
    • Added example demonstrating how to create a contact event.
  • Tests

    • Added comprehensive tests for contact event creation, including success cases and common error scenarios (not found, validation, auth, rate limits).

Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds a new Contact API method to create contact events, introduces a corresponding DTO, updates examples to demonstrate event creation, extends tests to cover success and error cases, and updates README with new capability bullets.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added bullets: Email API/SMTP “Sending domain management CRUD”, Import “Events”, General “Billing info”.
API: Contact events
src/Api/General/Contact.php
New method createContactEvent(string $contactIdentifier, CreateContactEvent $event): ResponseInterface posting to .../contacts/{encodedId}/events; integrates DTO and response handling.
DTO: CreateContactEvent
src/DTO/Request/Contact/CreateContactEvent.php
New final DTO implementing RequestInterface with name, params, init(...), getters, and toArray() for request payload.
Examples
examples/general/contacts.php
Added sample demonstrating createContactEvent call using CreateContactEvent::init(...) with try/catch and output.
Tests
tests/Api/General/ContactTest.php
Added 9 tests covering success, email vs ID identifiers, empty params, and error scenarios (404, 422, 401, 403, complex 422, 429); validates URL encoding and payload.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Developer Code
    participant SDK as Contact API (createContactEvent)
    participant HTTP as HTTP Client
    participant SVC as Mailtrap API

    Dev->>SDK: createContactEvent(contactIdentifier, CreateContactEvent)
    SDK->>HTTP: POST /contacts/{encoded(contactIdentifier)}/events\nbody: { name, params }
    HTTP->>SVC: Request
    alt Success
        SVC-->>HTTP: 2xx Response
        HTTP-->>SDK: ResponseInterface
        SDK-->>Dev: ResponseInterface
    else Error
        SVC-->>HTTP: 4xx/5xx Error
        HTTP-->>SDK: Error details
        SDK-->>Dev: Exception (HttpClientException)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • leonid-shevtsov
  • IgorDobryn
  • i7an
  • mklocek
  • VladimirTaytor

Poem

I thump my paw, events now hop—hooray!
Contacts blink; their logins light the way.
A DTO bouquet, neat and compact,
Tests nibble errors, every edge intact.
README sprouts bullets—fresh and bright—
Ship it swift, into the carrot-light! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% 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
Title Check ✅ Passed The title "Add contact event functionality" is concise and accurately reflects the primary change in the changeset—adding CreateContactEvent support (DTO, API method, tests, and examples); it is focused, clear, and useful for a teammate scanning history.
Description Check ✅ Passed The PR description includes the required high-level sections from the template—Motivation, Changes, and How to test—and supplies a test command, so it is mostly complete and on-topic for reviewers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/contact-events

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@gaalferov gaalferov linked an issue Sep 18, 2025 that may be closed by this pull request
@gaalferov gaalferov changed the title Add CreateContactEvent functionality and related tests Add contact event functionality Sep 18, 2025
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

🧹 Nitpick comments (2)
CHANGELOG.md (2)

1-1: Future-dated release entry — use “Unreleased” until tag, or update on release day

The 3.8.0 entry is dated 2025-09-22, which is in the future relative to today (2025-09-18). Suggest marking as Unreleased until tagging, then replace with the actual release date.

Option A — keep as Unreleased for now:

-## [3.8.0] - 2025-09-22
+## [Unreleased]

Option B — if you are tagging 3.8.0 today, update the date:

-## [3.8.0] - 2025-09-22
+## [3.8.0] - 2025-09-18

2-2: Capitalize “Event” for consistency

Prior entries use Title Case (e.g., “Contact Imports”, “Contact Fields”). Align this one to “Create Contact Event”.

-- Add Create Contact event API functionality
+- Add Create Contact Event API functionality
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6232ba and f299317.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • README.md (2 hunks)
  • examples/general/contacts.php (2 hunks)
  • src/Api/General/Contact.php (2 hunks)
  • src/DTO/Request/Contact/CreateContactEvent.php (1 hunks)
  • tests/Api/General/ContactTest.php (2 hunks)
🔥 Files not summarized due to errors (1)
  • CHANGELOG.md: Error: Server error: no LLM provider could handle the message
🧰 Additional context used
🧬 Code graph analysis (4)
src/DTO/Request/Contact/CreateContactEvent.php (1)
src/Api/General/Contact.php (1)
  • Contact (19-363)
src/Api/General/Contact.php (2)
src/DTO/Request/Contact/CreateContactEvent.php (2)
  • CreateContactEvent (12-42)
  • toArray (35-41)
src/Api/AbstractApi.php (2)
  • handleResponse (84-111)
  • httpPost (43-50)
examples/general/contacts.php (3)
src/Api/General/Contact.php (2)
  • Contact (19-363)
  • createContactEvent (301-309)
src/DTO/Request/Contact/CreateContactEvent.php (3)
  • CreateContactEvent (12-42)
  • init (20-23)
  • toArray (35-41)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
tests/Api/General/ContactTest.php (8)
src/Api/General/Contact.php (2)
  • Contact (19-363)
  • createContactEvent (301-309)
src/DTO/Request/Contact/CreateContactEvent.php (2)
  • CreateContactEvent (12-42)
  • toArray (35-41)
src/Api/AbstractApi.php (1)
  • AbstractApi (18-150)
src/DTO/Request/Contact/ImportContact.php (1)
  • toArray (49-57)
src/DTO/Request/Contact/UpdateContact.php (1)
  • toArray (56-68)
src/DTO/Request/Contact/CreateContact.php (1)
  • toArray (39-46)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/Exception/HttpClientException.php (1)
  • HttpClientException (14-84)
🔇 Additional comments (11)
README.md (1)

25-25: Documentation is accurately updated to reflect new capabilities.

The README correctly documents the three new capabilities added by this PR:

  • "Sending domain management CRUD" under Email API/SMTP
  • "Events" under Contact management/Import
  • "Billing info" under General

These additions accurately reflect the expanded feature set, with the "Events" capability directly related to the CreateContactEvent functionality introduced in this PR.

Also applies to: 38-38, 42-42

examples/general/contacts.php (2)

5-5: Import statement is correctly added.

The CreateContactEvent DTO is properly imported to support the new example.


326-350: Example demonstrates the new contact event functionality effectively.

The example correctly shows:

  1. Using email as the contact identifier
  2. Creating an event with CreateContactEvent::init()
  3. Including both required (name) and optional (params) fields
  4. Proper error handling with try-catch
  5. Displaying the response using ResponseHelper

The parameter structure with mixed types (int, string, bool, null) provides a comprehensive example.

src/Api/General/Contact.php (2)

10-10: Import statement correctly added for the new DTO.


294-309: The createContactEvent method implementation looks good.

The method correctly:

  1. Accepts a contact identifier (email or UUID) and CreateContactEvent DTO
  2. URL-encodes the contact identifier to handle special characters in emails
  3. Uses the DTO's toArray() method for the request body
  4. Follows the existing pattern used by other methods in this class
  5. Returns a ResponseInterface wrapped with handleResponse for error handling
src/DTO/Request/Contact/CreateContactEvent.php (1)

1-42: The CreateContactEvent DTO is well-structured and follows established patterns.

The implementation:

  1. Correctly implements RequestInterface
  2. Uses constructor property promotion (PHP 8 feature)
  3. Provides a static factory method init() consistent with other DTOs
  4. Implements toArray() for request serialization
  5. Makes params optional with a sensible default (empty array)
  6. Is marked as final to prevent inheritance
tests/Api/General/ContactTest.php (5)

8-8: Import statement correctly added for testing the new DTO.


657-699: The basic createContactEvent test is comprehensive.

The test properly verifies:

  1. URL encoding of the email identifier
  2. Correct request path construction
  3. Payload serialization via toArray()
  4. Response handling and data assertions

701-740: Test correctly validates UUID-based contact identification.

Good coverage of using a UUID instead of email as the contact identifier.


742-769: Empty params test validates optional parameter behavior.

Correctly verifies that events can be created without params, using the default empty array.


771-926: Excellent error handling test coverage.

The test suite comprehensively covers error scenarios:

  • 404: Contact not found
  • 422: Validation errors (empty name, complex validation errors)
  • 401: Authentication failures
  • 403: Authorization failures
  • 429: Rate limiting

Each test properly validates the expected error message format.

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.

Contacts Events
2 participants