Skip to content

Commit 6bc7338

Browse files
committed
make first test passes
1 parent eb505e6 commit 6bc7338

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

composer.json

-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
"php": "^8.4",
2020
"ext-curl": "*",
2121
"ext-json": "*",
22-
"guzzlehttp/guzzle": "7.x",
2322
"illuminate/contracts": "^10.0||^11.0||^12.0",
24-
"league/oauth2-client": "^2",
2523
"spatie/laravel-data": "^4.15",
2624
"spatie/laravel-package-tools": "^1.16"
2725
},

src/DTOs/SubscribersDTO.php

+9-14
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Coderflex\LaravelSendy\DTOs;
44

5+
use Spatie\LaravelData\Attributes\MergeValidationRules;
56
use Spatie\LaravelData\Data;
67
use Spatie\LaravelData\Support\Validation\ValidationContext;
78

9+
#[MergeValidationRules]
810
class SubscribersDTO extends Data
911
{
1012
public function __construct(
@@ -19,18 +21,11 @@ public function __construct(
1921
public ?bool $boolean,
2022
) {}
2123

22-
// public static function rules(ValidationContext $context): array
23-
// {
24-
// return [
25-
// 'name' => ['string', 'nullable'],
26-
// 'email' => ['required', 'string', 'email'],
27-
// 'list' => ['required', 'string'],
28-
// 'country' => ['string', 'nullable'],
29-
// 'ipaddress' => ['string', 'nullable', 'ip'],
30-
// 'referrer' => ['string', 'nullable'],
31-
// 'gdpr' => ['boolean', 'nullable'],
32-
// 'silent' => ['boolean', 'nullable'],
33-
// 'boolean' => ['boolean', 'nullable'],
34-
// ];
35-
// }
24+
public static function rules(ValidationContext $context): array
25+
{
26+
return [
27+
'email' => ['email'],
28+
'ipaddress' => ['ip'],
29+
];
30+
}
3631
}

src/LaravelSendy.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,8 @@ public function __call(string $function, array $args): mixed
6969
/**
7070
* @throws \Exception
7171
*/
72-
protected function sendRequest(
73-
string $type,
74-
string $request,
75-
array $data = [],
76-
array $headers = [],
77-
bool $async = false
78-
): mixed {
72+
protected function sendRequest(string $type, string $request, array $data = [], array $headers = [], bool $async = false): mixed
73+
{
7974
try {
8075
$mainHeaders = array_merge([
8176
'Content-Type' => 'application/json',
@@ -86,7 +81,7 @@ protected function sendRequest(
8681
'api_key' => $this->apiKey,
8782
]);
8883

89-
$url = str_replace('//', '/', "$this->apiUrl/$request");
84+
$url = rtrim($this->apiUrl, '/').'/'.ltrim($request, '/');
9085

9186
$client = Http::withHeaders($headers);
9287

src/Resources/Subscribers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Subscribers
99
{
1010
public function subscribe(array $data, bool $async = false)
1111
{
12-
$data = SubscribersDTO::validateAndCreate($data)->toArray();
12+
$data = SubscribersDTO::validate($data);
1313

1414
return LaravelSendy::post('subscribe', $data, $async);
1515
}

tests/Resources/SubscribersTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'country' => 'UAE',
2323
]);
2424

25-
expect($response)->toBe(['success' => true]);
25+
expect($response->json())->toBe(['success' => true]);
2626

2727
Http::assertSent(function ($request) {
2828
return $request->url() === 'https://sendy.test/subscribe' &&

0 commit comments

Comments
 (0)