-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathCheckPackageUrlAvailabilityCommandTest.php
More file actions
88 lines (73 loc) · 2.81 KB
/
Copy pathCheckPackageUrlAvailabilityCommandTest.php
File metadata and controls
88 lines (73 loc) · 2.81 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
use App\Console\Commands\CheckPackageUrls;
use App\Models\Collaborator;
use App\Models\Package;
use App\Models\User;
use App\Notifications\NotifyAuthorOfUnavailablePackageUrl;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Notification;
beforeEach(function () {
$this->validPackage = Package::factory()->create([
'name' => 'Valid Package',
'url' => 'https://github.com/tighten/novapackages',
'repo_url' => 'https://github.com/tighten/novapackages',
'author_id' => Collaborator::factory()->create([
'user_id' => User::factory()->create()->id,
])->id,
]);
$this->packageWithUnavailableUrl = Package::factory()->create([
'name' => 'Package with Unavailable URL',
'url' => 'https://github.com/some-dev/package-name',
'repo_url' => 'https://github.com/some-dev/package-name',
'author_id' => Collaborator::factory()->create([
'user_id' => User::factory()->create()->id,
])->id,
]);
$this->packageWithUnavailableDomain = Package::factory()->create([
'name' => 'Package with Unavailable Domain',
'url' => 'https://not-github.com/other-dev/package-name',
'repo_url' => 'https://github.com/tighten/novapackages',
]);
});
test('calling command marks unavailable packages as unavailable', function () {
Notification::fake();
$now = now();
Carbon::setTestNow($now);
$this->artisan(CheckPackageUrls::class);
expect($this->validPackage->marked_as_unavailable_at)->toBeNull();
$this->assertEquals(
$this->packageWithUnavailableUrl->refresh()->marked_as_unavailable_at,
$now
);
$this->assertEquals(
$this->packageWithUnavailableDomain->refresh()->marked_as_unavailable_at,
$now
);
});
test('calling command sends notification to author of unavailable packages', function () {
Notification::fake();
Http::fake([
$this->validPackage->url => Http::response(null, 200),
$this->packageWithUnavailableUrl->url => Http::response(null, 404),
]);
$this->artisan(CheckPackageUrls::class);
Notification::assertNotSentTo(
$this->validPackage->author->user,
NotifyAuthorOfUnavailablePackageUrl::class
);
Notification::assertSentTo(
$this->packageWithUnavailableUrl->author->user,
NotifyAuthorOfUnavailablePackageUrl::class,
);
});
test('command ignores packages that are already unavailable', function () {
Notification::fake();
$this->packageWithUnavailableUrl->marked_as_unavailable_at = now();
$this->packageWithUnavailableUrl->save();
$this->artisan(CheckPackageUrls::class);
Notification::assertNotSentTo(
$this->packageWithUnavailableUrl->author->user,
NotifyAuthorOfUnavailablePackageUrl::class,
);
});