Skip to content

Commit b6fbf3e

Browse files
committed
add campaign tests
1 parent d34e3e7 commit b6fbf3e

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

src/DTOs/CompaignDTO.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(
1919
public string $segment_ids,
2020
public ?string $exclude_list_ids,
2121
public ?string $exclude_segment_ids,
22-
public string $brand_id,
22+
public ?string $brand_id,
2323
public ?string $query_string,
2424
public ?int $track_opens,
2525
public ?int $track_clicks,
@@ -42,7 +42,7 @@ public static function rules(ValidationContext $context): array
4242
'segment_ids' => ['required', 'string'],
4343
'exclude_list_ids' => ['string', 'nullable'],
4444
'exclude_segment_ids' => ['string', 'nullable'],
45-
'brand_id' => ['required', 'string'],
45+
'brand_id' => ['required_if', 'string'],
4646
'query_string' => ['string', 'nullable'],
4747
'track_opens' => ['integer', 'nullable', 'in:0,1,2'],
4848
'track_clicks' => ['integer', 'nullable', 'in:0,1,2'],

src/Facades/LaravelSendy.php

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
/**
88
* @see \Coderflex\LaravelSendy\LaravelSendy
9+
*
10+
* @method static \Coderflex\LaravelSendy\Resources\Subscribers subscribers()
11+
* @method static \Coderflex\LaravelSendy\Resources\Lists lists()
12+
* @method static \Coderflex\LaravelSendy\Resources\Brands brands()
13+
* @method static \Coderflex\LaravelSendy\Resources\Campaigns campaigns()
14+
* @method static \Illuminate\Http\Client\Response get(string $path, array $data = [], bool $async = false, array $headers = [])
15+
* @method static \Illuminate\Http\Client\Response post(string $path, array $data = [], bool $async = false, array $headers = [])
16+
* @method static \Illuminate\Http\Client\Response put(string $path, array $data = [], bool $async = false, array $headers = [])
17+
* @method static \Illuminate\Http\Client\Response delete(string $path, array $data = [], bool $async = false, array $headers = [])
18+
* @method static \Illuminate\Http\Client\Response patch(string $path, array $data = [], bool $async = false, array $headers = [])
919
*/
1020
class LaravelSendy extends Facade
1121
{

src/Resources/Campaigns.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Campaigns
99
{
1010
public function create(array $data)
1111
{
12-
$data = CompaignDTO::validateAndCreate($data)->toArray();
12+
$data = CompaignDTO::validate($data);
1313

1414
return LaravelSendy::post('/api/campaigns/create.php', $data);
1515
}

tests/Resources/CompaignsTest.php

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
<?php
22

3-
//
3+
use Coderflex\LaravelSendy\Facades\LaravelSendy;
4+
use Illuminate\Support\Facades\Http;
5+
6+
beforeEach(function () {
7+
config([
8+
'laravel-sendy.api_key' => 'test_api_key',
9+
'laravel-sendy.api_url' => 'https://sendy.test/',
10+
]);
11+
});
12+
13+
it('can create and send a campaigns', function () {
14+
Http::fake([
15+
'https://sendy.test/api/campaigns/create.php' => Http::response(['status' => 'Campaign created and now sending'], 200),
16+
]);
17+
18+
$response = LaravelSendy::campaigns()->create([
19+
'subject' => 'Test Subject',
20+
'from_name' => 'John Doe',
21+
'from_email' => '[email protected]',
22+
'reply_to' => '[email protected]',
23+
'title' => 'Test Title',
24+
'plain_text' => 'This is a plain text version of the email.',
25+
'html_text' => '<h1>This is a HTML version of the email.</h1>',
26+
'list_ids' => 'abc123',
27+
'segment_ids' => 'xyz456',
28+
'exclude_list_ids' => null,
29+
'exclude_segment_ids' => null,
30+
'brand_id' => 'brand123',
31+
'query_string' => null,
32+
'track_opens' => 1,
33+
'track_clicks' => 1,
34+
'send_compaign' => 1,
35+
'schedule_date_time' => null,
36+
'schedule_timezone' => null,
37+
]);
38+
39+
expect($response->json())->toBe(['status' => 'Campaign created and now sending']);
40+
41+
Http::assertSent(function ($request) {
42+
return $request->url() === 'https://sendy.test/api/campaigns/create.php' &&
43+
$request['from_email'] === '[email protected]' &&
44+
$request['from_name'] === 'John Doe' &&
45+
$request['api_key'] === 'test_api_key';
46+
});
47+
});

0 commit comments

Comments
 (0)