-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelTest.php
More file actions
executable file
·60 lines (49 loc) · 2.49 KB
/
ChannelTest.php
File metadata and controls
executable file
·60 lines (49 loc) · 2.49 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
<?php
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Statamic\Facades\User;
use TransformStudios\Front\Notifications\BaseNotification;
use TransformStudios\Front\Notifications\Channel;
beforeEach(function () {
config()->set('front.notifications.channel', 'test-channel');
Http::preventStrayRequests();
Http::fake([
'https://api2.frontapp.com/channels/test-channel/messages' => Http::response([
'_links' => [
'related' => [
'conversation' => 'https://transform-studios.api.frontapp.com/conversations/cnv_id',
],
],
], 200),
'https://api2.frontapp.com/conversations/cnv_id/messages' => Http::response([], 200),
]);
});
test('can send front message', function () {
$users = collect([makeUser('erin@transformstudios.com'), makeUser('erin@silentz.co')]);
$notification = new TestNotification('some-key', 'Monitor Alert: Error Detected', '', $users);
expect((new Channel)->send(new AnonymousNotifiable, $notification))->toBeTrue();
});
it('stores the conversation id', function () {
$notification = new TestNotification('some-key', 'Monitor Alert: Error Detected', '', collect([makeUser('foo@bar.com')]));
expect(Cache::get('some-key'))->toBeNull();
expect((new Channel)->send(new AnonymousNotifiable, $notification))->toBeTrue();
expect(Cache::get('some-key'))->toEqual('cnv_id');
});
it('removes the conversation id when alert cleared', function () {
$notification = new TestNotification('some-key', 'Monitor Alert: Error Cleared', '', collect([makeUser('foo@bar.com')]));
Cache::put('some-key', 'cnv_id');
expect(Cache::get('some-key'))->not->toBeNull();
expect((new Channel)->send(new AnonymousNotifiable, $notification))->toBeTrue();
expect(Cache::get('some-key'))->toBeNull();
});
it('adds to the conversation when conversation id exists', function () {
$user = makeUser('foo@bar.com');
$notification = new TestNotification('some-key', 'Monitor Alert: Error Detected', '', collect([$user]));
$anotherNotification = new TestNotification('some-key', 'Monitor Alert: Error Cleared', '', collect([$user]));
$channel = new Channel;
expect($channel->send(new AnonymousNotifiable, $notification))->toBeTrue();
expect($channel->send(new AnonymousNotifiable, $anotherNotification))->toBeTrue();
});
class TestNotification extends BaseNotification {}