|
12 | 12 |
|
13 | 13 | it('can subscribe a user', function () {
|
14 | 14 | Http::fake([
|
15 |
| - 'https://sendy.test/subscribe' => Http::response(['success' => true], 200), |
| 15 | + 'https://sendy.test/subscribe' => Http::response(true, 200), |
16 | 16 | ]);
|
17 | 17 |
|
18 | 18 | $response = LaravelSendy::subscribers()->subscribe([
|
|
22 | 22 | 'country' => 'UAE',
|
23 | 23 | ]);
|
24 | 24 |
|
25 |
| - expect($response->json())->toBe(['success' => true]); |
| 25 | + expect($response->json())->toBe(1); |
26 | 26 |
|
27 | 27 | Http::assertSent(function ($request) {
|
28 | 28 | return $request->url() === 'https://sendy.test/subscribe' &&
|
|
31 | 31 | $request['api_key'] === 'test_api_key';
|
32 | 32 | });
|
33 | 33 | });
|
| 34 | + |
| 35 | +it('can unsubscribe a user', function () { |
| 36 | + Http::fake([ |
| 37 | + 'https://sendy.test/api/subscribers/unsubscribe.php' => Http::response(true, 200), |
| 38 | + ]); |
| 39 | + |
| 40 | + $response = LaravelSendy::subscribers()->unsubscribe([ |
| 41 | + 'list' => 123, |
| 42 | + |
| 43 | + 'boolean' => true, |
| 44 | + ]); |
| 45 | + |
| 46 | + expect($response->json())->toBe(1); |
| 47 | + |
| 48 | + Http::assertSent(function ($request) { |
| 49 | + return $request->url() === 'https://sendy.test/api/subscribers/unsubscribe.php' && |
| 50 | + $request[ 'email'] === '[email protected]' && |
| 51 | + $request['list'] === 123; |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +it('can delete a subscriber', function () { |
| 56 | + Http::fake([ |
| 57 | + 'https://sendy.test/api/subscribers/delete.php' => Http::response(true, 200), |
| 58 | + ]); |
| 59 | + |
| 60 | + $response = LaravelSendy::subscribers()->delete([ |
| 61 | + 'list_id' => 123, |
| 62 | + |
| 63 | + ]); |
| 64 | + |
| 65 | + expect($response->json())->toBe(1); |
| 66 | + |
| 67 | + Http:: assertSent( fn ( $request) => $request[ 'email'] === '[email protected]' && |
| 68 | + $request['list_id'] === 123 |
| 69 | + ); |
| 70 | +}); |
| 71 | + |
| 72 | +it('can get subscriber status', function () { |
| 73 | + Http::fake([ |
| 74 | + 'https://sendy.test/api/subscribers/subscription-status.php' => Http::response(['status' => 'Subscribed'], 200), |
| 75 | + ]); |
| 76 | + |
| 77 | + $response = LaravelSendy::subscribers()->status([ |
| 78 | + 'list_id' => 123, |
| 79 | + |
| 80 | + ]); |
| 81 | + |
| 82 | + expect($response->json())->toBe(['status' => 'Subscribed']); |
| 83 | +}); |
| 84 | + |
| 85 | +it('can get subscriber count', function () { |
| 86 | + Http::fake([ |
| 87 | + 'https://sendy.test/api/subscribers/subscriber-count.php' => Http::response(25, 200), |
| 88 | + ]); |
| 89 | + |
| 90 | + $response = LaravelSendy::subscribers()->count(123); |
| 91 | + |
| 92 | + expect($response->json())->toBe(25); |
| 93 | +}); |
0 commit comments