|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use NotificationChannels\Telegram\TelegramLocation;
|
| 4 | +use NotificationChannels\Telegram\Tests\TestSupport\TestLocationNotification; |
| 5 | +use NotificationChannels\Telegram\Tests\TestSupport\TestNotifiable; |
4 | 6 |
|
5 |
| -const TEST_LONG = -77.0364; |
6 | 7 | const TEST_LAT = 38.8951;
|
| 8 | +const TEST_LONG = -77.0364; |
7 | 9 |
|
8 | 10 | it('accepts content when constructed', function () {
|
9 |
| - $message = new TelegramLocation(TEST_LONG, TEST_LAT); |
| 11 | + $message = new TelegramLocation(TEST_LAT, TEST_LONG); |
10 | 12 | expect($message->getPayloadValue('latitude'))
|
11 |
| - ->toEqual(TEST_LONG) |
| 13 | + ->toEqual(TEST_LAT) |
12 | 14 | ->and($message->getPayloadValue('longitude'))
|
13 |
| - ->toEqual(TEST_LAT); |
| 15 | + ->toEqual(TEST_LONG); |
14 | 16 | });
|
15 | 17 |
|
16 | 18 | it('accepts content when created', function () {
|
17 |
| - $message = TelegramLocation::create(TEST_LONG, TEST_LAT); |
| 19 | + $message = TelegramLocation::create(TEST_LAT, TEST_LONG); |
18 | 20 | expect($message->getPayloadValue('latitude'))
|
19 |
| - ->toEqual(TEST_LONG) |
| 21 | + ->toEqual(TEST_LAT) |
20 | 22 | ->and($message->getPayloadValue('longitude'))
|
21 |
| - ->toEqual(TEST_LAT); |
| 23 | + ->toEqual(TEST_LONG); |
22 | 24 | });
|
23 | 25 |
|
24 | 26 | test('the recipients chat id can be set', function () {
|
|
27 | 29 | expect($message->getPayloadValue('chat_id'))->toEqual(12345);
|
28 | 30 | });
|
29 | 31 |
|
30 |
| -test('the notification longitude can be set', function () { |
| 32 | +test('the notification latitude can be set', function () { |
31 | 33 | $message = new TelegramLocation();
|
32 |
| - $message->longitude(TEST_LAT); |
33 |
| - expect($message->getPayloadValue('longitude'))->toEqual(TEST_LAT); |
| 34 | + $message->latitude(TEST_LAT); |
| 35 | + expect($message->getPayloadValue('latitude'))->toEqual(TEST_LAT); |
34 | 36 | });
|
35 | 37 |
|
36 |
| -test('the notification latitude can be set', function () { |
| 38 | +test('the notification longitude can be set', function () { |
37 | 39 | $message = new TelegramLocation();
|
38 |
| - $message->latitude(TEST_LONG); |
39 |
| - expect($message->getPayloadValue('latitude'))->toEqual(TEST_LONG); |
| 40 | + $message->longitude(TEST_LONG); |
| 41 | + expect($message->getPayloadValue('longitude'))->toEqual(TEST_LONG); |
40 | 42 | });
|
41 | 43 |
|
42 | 44 | test('additional options can be set for the message', function () {
|
|
54 | 56 | });
|
55 | 57 |
|
56 | 58 | it('can return the payload as an array', function () {
|
57 |
| - $message = new TelegramLocation(TEST_LONG, TEST_LAT); |
| 59 | + $message = new TelegramLocation(TEST_LAT, TEST_LONG); |
58 | 60 | $message->to(12345);
|
59 | 61 | $message->options(['foo' => 'bar']);
|
60 | 62 | $expected = [
|
61 | 63 | 'chat_id' => 12345,
|
62 | 64 | 'foo' => 'bar',
|
63 |
| - 'longitude' => TEST_LAT, |
64 |
| - 'latitude' => TEST_LONG, |
| 65 | + 'latitude' => TEST_LAT, |
| 66 | + 'longitude' => TEST_LONG, |
65 | 67 | ];
|
66 | 68 |
|
67 | 69 | expect($message->toArray())->toEqual($expected);
|
68 | 70 | });
|
| 71 | + |
| 72 | +it('can send a location', function () { |
| 73 | + $notifiable = new TestNotifiable(); |
| 74 | + $notification = new TestLocationNotification(TEST_LAT, TEST_LONG); |
| 75 | + |
| 76 | + $expectedResponse = $this->makeMockResponse([ |
| 77 | + 'location' => collect($notification->toTelegram($notifiable)->toArray())->except('chat_id')->toArray(), |
| 78 | + ]); |
| 79 | + |
| 80 | + $actualResponse = $this->sendMockNotification('sendLocation', $notifiable, $notification, $expectedResponse); |
| 81 | + |
| 82 | + expect($actualResponse)->toBe($expectedResponse); |
| 83 | +}); |
0 commit comments