Skip to content

test: characterization tests for outbound webhook job#196

Open
dan2k3k4 wants to merge 2 commits into
devfrom
advisor/006-webhook-job-characterization-tests
Open

test: characterization tests for outbound webhook job#196
dan2k3k4 wants to merge 2 commits into
devfrom
advisor/006-webhook-job-characterization-tests

Conversation

@dan2k3k4

@dan2k3k4 dan2k3k4 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Adds test coverage for the outbound webhook delivery job (success, non-success response, and transport-error handling).

Greptile Summary

This PR adds characterization tests for ProcessPolydockStoreWebhookCall and improves both webhook factories with proper relational defaults and correct enum values.

  • Factory improvements: PolydockStoreWebhookCallFactory now uses PolydockStoreWebhook::factory(), the PENDING enum default, and null response fields; PolydockStoreWebhookFactory gains the missing polydock_store_id key — both changes make the factories work correctly in isolation.
  • Three test cases: Covers the 2xx success path, non-2xx failure path (which re-sets status to PENDING on the first attempt via the catch block), and the transport-exception path — assertions match the actual job implementation accurately.
  • Not yet covered: The failed() callback (permanent failure after all retries) is not exercised; calling $job->failed($e) directly in a fourth test would complete the coverage.

Confidence Score: 5/5

Test-only change with factory improvements; no production code is modified and all assertions match the actual job implementation.

All three test assertions are verified against the real job code — status transitions, response fields, exception capture, and HTTP header checks are correct. The factory fixes remove incorrect placeholder values that could have caused unrelated tests to fail silently. No production code paths are altered.

No files require special attention; the test file has two minor style/coverage observations but nothing that blocks merging.

Important Files Changed

Filename Overview
database/factories/PolydockStoreWebhookCallFactory.php Replaces random fake strings with proper relational factory (PolydockStoreWebhook::factory()), correct enum default (PENDING), and semantically-appropriate null defaults for response fields.
database/factories/PolydockStoreWebhookFactory.php Adds the missing polydock_store_id foreign key wired to PolydockStore::factory(), making standalone factory creation work without a pre-existing store record.
tests/Feature/Jobs/ProcessPolydockStoreWebhookCallTest.php New characterization test file covering the three main execution paths of ProcessPolydockStoreWebhookCall::handle(); assertions are accurate against the real job code. Minor note: Bus::fake() is tucked inside the makeWebhookCall() helper and the failed() callback is not yet exercised.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant T as Test
    participant J as ProcessPolydockStoreWebhookCall
    participant DB as Database
    participant H as Http (faked)

    T->>DB: "factory()->create() [Bus faked, auto-dispatch suppressed]"
    T->>J: "new Job($call)->handle()"
    J->>DB: "update(status=PROCESSING, attempt=1)"
    J->>H: POST webhook URL with headers

    alt 2xx response
        H-->>J: 200 OK
        J->>DB: "update(status=SUCCESS, response_code, response_body, processed_at)"
        J-->>T: returns void
    else Non-2xx response
        H-->>J: 500 Error
        J->>DB: "update(status=FAILED, response_code, response_body, processed_at)"
        J->>J: throw Exception
        J->>DB: "catch: update(status=PENDING, processed_at, exception)"
        J-->>T: rethrow Exception
    else Transport Exception
        H-->>J: throws ConnectionException
        J->>DB: "catch: update(status=PENDING, processed_at, exception)"
        J-->>T: rethrow ConnectionException
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant T as Test
    participant J as ProcessPolydockStoreWebhookCall
    participant DB as Database
    participant H as Http (faked)

    T->>DB: "factory()->create() [Bus faked, auto-dispatch suppressed]"
    T->>J: "new Job($call)->handle()"
    J->>DB: "update(status=PROCESSING, attempt=1)"
    J->>H: POST webhook URL with headers

    alt 2xx response
        H-->>J: 200 OK
        J->>DB: "update(status=SUCCESS, response_code, response_body, processed_at)"
        J-->>T: returns void
    else Non-2xx response
        H-->>J: 500 Error
        J->>DB: "update(status=FAILED, response_code, response_body, processed_at)"
        J->>J: throw Exception
        J->>DB: "catch: update(status=PENDING, processed_at, exception)"
        J-->>T: rethrow Exception
    else Transport Exception
        H-->>J: throws ConnectionException
        J->>DB: "catch: update(status=PENDING, processed_at, exception)"
        J-->>T: rethrow ConnectionException
    end
Loading

Reviews (2): Last reviewed commit: "test: correct attempts() comment and ass..." | Re-trigger Greptile

Comment thread tests/Feature/Jobs/ProcessPolydockStoreWebhookCallTest.php
Comment thread tests/Feature/Jobs/ProcessPolydockStoreWebhookCallTest.php
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.

1 participant