PHP Classes

File: tests/Unit/Data/WebhookEndpointTest.php

Recommend this page to a friend!
  Packages of Daryl Legion   PayRex Laravel   tests/Unit/Data/WebhookEndpointTest.php   Download  
File: tests/Unit/Data/WebhookEndpointTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PayRex Laravel
Request payments using the PayRex service
Author: By
Last change:
Date: 13 days ago
Size: 1,359 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
LegionHQ\LaravelPayrex\Data\WebhookEndpoint;
use
LegionHQ\LaravelPayrex\Enums\WebhookEndpointStatus;

it('hydrates all properties from fixture', function () {
   
$data = loadFixture('webhook/created.json');
   
$webhook = WebhookEndpoint::from($data);

   
expect($webhook->id)->toBe('wh_xxxxx')
        ->
and($webhook->resource)->toBe('webhook')
        ->
and($webhook->secretKey)->toBe('whsk_xxxxx')
        ->
and($webhook->url)->toBe('https://my-ecommerce.com/send-shipments')
        ->
and($webhook->events)->toBe(['payment_intent.succeeded'])
        ->
and($webhook->description)->toBe('This is the webhook used for sending shipments after receiving successfully paid payments')
        ->
and($webhook->livemode)->toBeFalse();
});

it('casts status to WebhookEndpointStatus enum', function () {
   
expect((WebhookEndpoint::from(['id' => 'wh_1', 'resource' => 'webhook', 'status' => 'enabled']))->status)->toBe(WebhookEndpointStatus::Enabled)
        ->
and((WebhookEndpoint::from(['id' => 'wh_2', 'resource' => 'webhook', 'status' => 'disabled']))->status)->toBe(WebhookEndpointStatus::Disabled);
});

it('returns null for unknown status values', function () {
   
$webhook = WebhookEndpoint::from(['id' => 'wh_1', 'resource' => 'webhook', 'status' => 'nonexistent']);

   
expect($webhook->status)->toBeNull();
});