| @@ 52-87 (lines=36) @@ | ||
| 49 | } |
|
| 50 | ||
| 51 | /** @test */ |
|
| 52 | function via_custom() { |
|
| 53 | ||
| 54 | $checks = ['diskspace']; |
|
| 55 | ||
| 56 | $host = Host::create([ |
|
| 57 | 'name' => 'test2', |
|
| 58 | 'port' => 22, |
|
| 59 | ]); |
|
| 60 | ||
| 61 | $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
| 62 | return new Check([ |
|
| 63 | 'type' => $checkName, |
|
| 64 | 'status' => CheckStatus::NOT_YET_CHECKED, |
|
| 65 | ]); |
|
| 66 | })); |
|
| 67 | ||
| 68 | $event = new \Spatie\ServerMonitor\Events\CheckSucceeded($host->checks()->first()); |
|
| 69 | $this->notifiable->setEvent($event); |
|
| 70 | ||
| 71 | $host = $this->notifiable->getEvent()->check->host()->first(); |
|
| 72 | $notifications = [ |
|
| 73 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckSucceeded' => |
|
| 74 | [ |
|
| 75 | 'channels' => ['mail'] |
|
| 76 | ], |
|
| 77 | 'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]] |
|
| 78 | ]; |
|
| 79 | ||
| 80 | $host->setCustomProperty('notifications', $notifications); |
|
| 81 | ||
| 82 | $host->save(); |
|
| 83 | ||
| 84 | $check = new CheckFailed(); |
|
| 85 | $result = $check->via($this->notifiable); |
|
| 86 | $this->assertCount(0, $result); |
|
| 87 | } |
|
| 88 | ||
| 89 | /** @test */ |
|
| 90 | function via_custom_notifiation_exist() { |
|
| @@ 90-125 (lines=36) @@ | ||
| 87 | } |
|
| 88 | ||
| 89 | /** @test */ |
|
| 90 | function via_custom_notifiation_exist() { |
|
| 91 | ||
| 92 | $checks = ['diskspace']; |
|
| 93 | ||
| 94 | $host = Host::create([ |
|
| 95 | 'name' => 'test', |
|
| 96 | 'port' => 22, |
|
| 97 | ]); |
|
| 98 | ||
| 99 | $host->checks()->saveMany(collect($checks)->map(function (string $checkName) { |
|
| 100 | return new Check([ |
|
| 101 | 'type' => $checkName, |
|
| 102 | 'status' => CheckStatus::NOT_YET_CHECKED, |
|
| 103 | ]); |
|
| 104 | })); |
|
| 105 | ||
| 106 | $event = new \Spatie\ServerMonitor\Events\CheckSucceeded($host->checks()->first()); |
|
| 107 | $this->notifiable->setEvent($event); |
|
| 108 | ||
| 109 | $host = $this->notifiable->getEvent()->check->host()->first(); |
|
| 110 | $notifications = [ |
|
| 111 | 'TheCodingMachine\ServerMonitorPluginNotificationByHost\Notifications\Notifications\CheckFailed' => |
|
| 112 | [ |
|
| 113 | 'channels' => ['mail'] |
|
| 114 | ], |
|
| 115 | 'configuration' => ['mail' => [ 'to' => ['[email protected]'] ]] |
|
| 116 | ]; |
|
| 117 | ||
| 118 | $host->setCustomProperty('notifications', $notifications); |
|
| 119 | ||
| 120 | $host->save(); |
|
| 121 | ||
| 122 | $check = new CheckFailed(); |
|
| 123 | $result = $check->via($this->notifiable); |
|
| 124 | $this->assertSame('mail', $result[0]); |
|
| 125 | } |
|
| 126 | } |
|
| 127 | ||