Files
warp_engine/spec/requests/software_controller_spec.rb
T
mr.zeroandClaude Fable 5 2b2a9df136 Phase 4: move catalog controllers and routes into WarpEngine
- update, files and the 6 /api catalog controllers now live in the engine on
  a new WarpEngine::ApiController base (same rescue/mime behavior as host)
- engine routes serve /update, /file/*path, /api/software*, /api/builds*,
  /api/image/:id, /api/download at unchanged public paths via the root mount;
  host routes keep only TTG endpoints (events, members, wiki, rss, swagger)
- /update secret comes from WarpEngine.config.update_secret and an
  unconfigured secret now rejects every request (previously an empty
  UPDATE_SECRET env accepted empty secrets)
- apipie-rails is an engine dependency (DSL in engine controllers); dummy app
  configures apipie with validation off, mirroring the host
- engine request specs: catalog controller specs moved from host plus new
  /update auth contract spec

Verified: engine suite 53 green, host suite 6 green, /api/software and
/api/builds byte-identical to baselines, /update 401/400 behavior intact,
admin and TTG endpoints OK.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 19:09:11 +02:00

43 lines
1.2 KiB
Ruby

require "rails_helper"
RSpec.describe "GET /api/software", type: :request do
describe "GET /api/software" do
it "returns all software with releases" do
create(:software, name: "test-game", title: "Test Game")
get "/api/software"
expect(response).to have_http_status(:ok)
json = JSON.parse(response.body)
expect(json["softwares"]).to be_an(Array)
expect(json["softwares"].length).to eq(1)
end
it "returns per-release and total download counts" do
software = create(:software)
release = create(:release, software: software)
other = create(:release, software: software)
create_list(:download, 3, release: release)
create(:download, release: other)
get "/api/software"
json = JSON.parse(response.body)
sw = json["softwares"].first
expect(sw["totalDownloads"]).to eq(4)
counts = sw["releases"].to_h { |r| [ r["id"], r["downloadCount"] ] }
expect(counts[release.id]).to eq(3)
expect(counts[other.id]).to eq(1)
end
it "excludes soft-deleted software" do
create(:software, deleted_at: Time.current)
get "/api/software"
json = JSON.parse(response.body)
expect(json["softwares"]).to be_empty
end
end
end