-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSyncPluginReleasesTest.php
More file actions
93 lines (77 loc) · 2.87 KB
/
SyncPluginReleasesTest.php
File metadata and controls
93 lines (77 loc) · 2.87 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
89
90
91
92
93
<?php
namespace Tests\Feature\Jobs;
use App\Jobs\SyncPluginReleases;
use App\Models\Plugin;
use App\Models\PluginVersion;
use App\Services\SatisService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class SyncPluginReleasesTest extends TestCase
{
use RefreshDatabase;
public function test_it_updates_latest_version_on_plugin_when_new_releases_are_synced(): void
{
Http::fake([
'api.github.com/repos/acme/test-plugin/releases*' => Http::response([
[
'id' => 1,
'tag_name' => 'v1.0.0',
'body' => 'Initial release',
'target_commitish' => 'abc123',
'published_at' => '2026-01-01T00:00:00Z',
],
[
'id' => 2,
'tag_name' => 'v1.1.0',
'body' => 'New features',
'target_commitish' => 'def456',
'published_at' => '2026-02-01T00:00:00Z',
],
]),
]);
$plugin = Plugin::factory()->create([
'name' => 'acme/test-plugin',
'repository_url' => 'https://github.com/acme/test-plugin',
'latest_version' => '0.9.0',
]);
$satisService = $this->mock(SatisService::class);
$job = new SyncPluginReleases($plugin, triggerSatisBuild: false);
$job->handle($satisService);
$plugin->refresh();
$this->assertEquals('1.1.0', $plugin->latest_version);
$this->assertCount(2, $plugin->versions);
}
public function test_it_does_not_update_latest_version_when_no_new_releases(): void
{
Http::fake([
'api.github.com/repos/acme/test-plugin/releases*' => Http::response([
[
'id' => 1,
'tag_name' => 'v1.0.0',
'body' => 'Initial release',
'target_commitish' => 'abc123',
'published_at' => '2026-01-01T00:00:00Z',
],
]),
]);
$plugin = Plugin::factory()->create([
'name' => 'acme/test-plugin',
'repository_url' => 'https://github.com/acme/test-plugin',
'latest_version' => '1.0.0',
]);
// Pre-create the version so nothing is "new"
PluginVersion::create([
'plugin_id' => $plugin->id,
'version' => '1.0.0',
'tag_name' => 'v1.0.0',
'github_release_id' => '1',
'published_at' => '2026-01-01T00:00:00Z',
]);
$satisService = $this->mock(SatisService::class);
$job = new SyncPluginReleases($plugin, triggerSatisBuild: false);
$job->handle($satisService);
$plugin->refresh();
$this->assertEquals('1.0.0', $plugin->latest_version);
}
}