This commit is contained in:
2026-08-06 19:23:04 +02:00
parent d05ed3c515
commit 161f923dc8
7 changed files with 87 additions and 107 deletions
+30 -28
View File
@@ -4,31 +4,6 @@ RSpec.describe WarpEngine::CiPipelineService do
let(:client) { instance_double(WarpEngine::WoodpeckerClient) }
let(:service) { described_class.new(client: client) }
describe "#dashboard" do
it "returns latest pipeline for each active repo" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game")
pipeline = { "number" => 5, "status" => "success", "created_at" => "2026-08-06T12:00:00Z" }
allow(client).to receive(:latest_pipeline).with(repo.woodpecker_repo_id).and_return(pipeline)
entries = service.dashboard
expect(entries.size).to eq(1)
expect(entries.first[:pipeline]["status"]).to eq("success")
expect(repo.reload.last_pipeline_status).to eq("success")
end
it "handles API errors gracefully per repo" do
create(:ci_repository, repo_owner: "org", repo_name: "broken")
allow(client).to receive(:latest_pipeline)
.and_raise(WarpEngine::WoodpeckerClient::ApiError.new("fail", status: 500))
entries = service.dashboard
expect(entries.size).to eq(1)
expect(entries.first[:pipeline]).to be_nil
end
end
describe "#trigger" do
it "delegates to client" do
repo = build(:ci_repository, repo_owner: "org", repo_name: "game")
@@ -42,12 +17,39 @@ RSpec.describe WarpEngine::CiPipelineService do
end
describe "#list_pipelines" do
it "returns paginated pipelines" do
repo = build(:ci_repository, repo_owner: "org", repo_name: "game")
pipelines = [{ "number" => 1 }, { "number" => 2 }]
it "returns paginated pipelines and refreshes the repo's cached last pipeline" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game")
pipelines = [
{ "number" => 2, "status" => "failure", "created" => 1_754_500_000 },
{ "number" => 1, "status" => "success", "created" => 1_754_400_000 }
]
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 1).and_return(pipelines)
expect(service.list_pipelines(repo)).to eq(pipelines)
repo.reload
expect(repo.last_pipeline_status).to eq("failure")
expect(repo.last_pipeline_at).to eq(Time.zone.at(1_754_500_000))
end
it "does not touch the cache on later pages" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game",
last_pipeline_status: "success")
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 2)
.and_return([{ "number" => 1, "status" => "failure", "created" => 1_754_400_000 }])
service.list_pipelines(repo, page: 2)
expect(repo.reload.last_pipeline_status).to eq("success")
end
it "leaves the cache alone when the repo has no pipelines" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game",
last_pipeline_status: "success")
allow(client).to receive(:list_pipelines).and_return([])
expect(service.list_pipelines(repo)).to eq([])
expect(repo.reload.last_pipeline_status).to eq("success")
end
end
end