-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBillingRequestBuilderTest.php
More file actions
102 lines (88 loc) · 3.61 KB
/
Copy pathCreateBillingRequestBuilderTest.php
File metadata and controls
102 lines (88 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
use Basement\AbacatePay\Billing\Enum\BillingFrequencyEnum;
use Basement\AbacatePay\Billing\Enum\BillingMethodEnum;
use Basement\AbacatePay\Billing\Http\Request\CreateBillingRequest;
use Basement\AbacatePay\Billing\Http\Request\ProductRequest;
use Basement\AbacatePay\Customer\Http\Request\CustomerRequest;
use Basement\AbacatePay\Exception\AbacatePayException;
beforeEach(function () {
$this->product = ProductRequest::builder()
->externalId('prod-123')
->name('Curso PHP')
->description('Curso completo de PHP moderno')
->quantity(1)
->price(15000)
->build();
$this->customer = CustomerRequest::builder()
->id('cust_abc123')
->name('João Silva')
->cellphone('+5511999999999')
->email('joao@email.com')
->taxId('12345678900')
->build();
});
it('should build a valid CreateBillingRequest', function () {
$request = CreateBillingRequest::oneTime()
->pix()
->returnUrl('https://retorno.exemplo.com')
->completionUrl('https://finalizacao.exemplo.com')
->addProduct($this->product)
->forCustomer($this->customer)
->build();
expect($request)
->toBeInstanceOf(CreateBillingRequest::class)
->and($request->frequency)->toBe(BillingFrequencyEnum::OneTime)
->and($request->methods)->toBe([BillingMethodEnum::Pix])
->and($request->products)->toHaveCount(1)
->and($request->customer->id)->toBe('cust_abc123')
->and($request->allow_coupons)->toBeFalse()
->and($request->coupons)->toBe([]);
});
it('should throw AbacatePayException when required fields are missing', function () {
expect(fn () => CreateBillingRequest::builder()->build())
->toThrow(AbacatePayException::class, 'Missing required fields');
});
it('should throw AbacatePayException when both customer and customerId are set', function () {
$builder = CreateBillingRequest::oneTime()
->pix()
->returnUrl('https://retorno.exemplo.com')
->completionUrl('https://finalizacao.exemplo.com')
->addProduct($this->product)
->forCustomer($this->customer)
->forCustomerId('cust_conflict');
expect(fn () => $builder->build())
->toThrow(InvalidArgumentException::class);
});
it('should allow optional fields to be omitted', function () {
$request = CreateBillingRequest::oneTime()
->pix()
->returnUrl('https://retorno.exemplo.com')
->completionUrl('https://finalizacao.exemplo.com')
->addProduct($this->product)
->build();
expect($request)
->toBeInstanceOf(CreateBillingRequest::class)
->and($request->externalId)->toBeNull()
->and($request->customerId)->toBeNull()
->and($request->customer)->toBeNull()
->and($request->coupons)->toBe([])
->and($request->allow_coupons)->toBeFalse();
});
it('should accept multiple methods and products', function () {
$product2 = ProductRequest::builder()
->externalId('prod-456')
->name('Curso Laravel')
->description('Aprenda Laravel com exemplos práticos')
->quantity(1)
->price(18000)
->build();
$request = CreateBillingRequest::multipleTimes()
->methods(BillingMethodEnum::Card, BillingMethodEnum::Pix)
->returnUrl('https://retorno.exemplo.com')
->completionUrl('https://finalizacao.exemplo.com')
->products($this->product, $product2)
->build();
expect($request->methods)->toBe([BillingMethodEnum::Card, BillingMethodEnum::Pix])
->and($request->products)->toHaveCount(2);
});