set('clusev.github_token', 'tok_secret'); config()->set('clusev.staging_slug', self::STAGING); config()->set('clusev.public_slug', self::PUBLIC_SLUG); config()->set('clusev.release_branch', 'feat/v1-foundation'); } public function test_deploy_public_dispatches_promote_public_with_the_tag(): void { Http::fake(['api.github.com/*' => Http::response('', 204)]); $this->assertTrue(app(PromotionService::class)->deployPublic('v0.10.0-rc1')); Http::assertSent(fn ($req) => $req->method() === 'POST' && str_contains($req->url(), 'repos/acme/staging/actions/workflows/promote-public.yml/dispatches') && $req['ref'] === 'feat/v1-foundation' && $req['inputs']['tag'] === 'v0.10.0-rc1' && $req->hasHeader('Authorization') && ! str_contains($req->url(), 'tok_secret')); } public function test_yank_dispatches_yank_with_the_tag(): void { Http::fake(['api.github.com/*' => Http::response('', 204)]); $this->assertTrue(app(PromotionService::class)->yank('v0.9.9')); Http::assertSent(fn ($req) => str_contains($req->url(), 'yank.yml/dispatches') && $req['inputs']['tag'] === 'v0.9.9'); } public function test_dispatch_returns_false_on_a_github_error(): void { Http::fake(['api.github.com/*' => Http::response('forbidden', 403)]); $this->assertFalse(app(PromotionService::class)->deployPublic('v0.10.0-rc1')); } public function test_dispatch_without_a_token_does_not_call_github(): void { config()->set('clusev.github_token', ''); Http::fake(); $this->assertFalse(app(PromotionService::class)->deployPublic('v0.10.0-rc1')); Http::assertNothingSent(); } public function test_public_tags_reads_the_public_repo_anonymously(): void { Http::fake(['api.github.com/repos/acme/public/tags*' => Http::response([['name' => 'v0.9.9'], ['name' => 'v0.9.8']])]); $this->assertSame(['v0.9.9', 'v0.9.8'], app(PromotionService::class)->publicTags()); Http::assertSent(fn ($req) => str_contains($req->url(), 'repos/acme/public/tags') && ! $req->hasHeader('Authorization')); } public function test_public_tags_is_empty_on_error(): void { Http::fake(['api.github.com/*' => Http::response('boom', 500)]); $this->assertSame([], app(PromotionService::class)->publicTags()); } }