update build_cancel spec
This commit is contained in:
parent
30d73782c8
commit
63bef443e8
|
@ -77,36 +77,148 @@ describe Travis::API::V3::Services::Build::Cancel do
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "existing repository, push access" do
|
describe "existing repository, push access, not cancelable" do
|
||||||
let(:params) {{}}
|
let(:params) {{}}
|
||||||
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
||||||
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
||||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
|
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
|
||||||
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
|
||||||
|
|
||||||
example { expect(last_response.status).to be == 202 }
|
describe "passed state" do
|
||||||
example { expect(JSON.load(body).to_s).to include(
|
before { build.update_attribute(:state, "passed") }
|
||||||
"@type",
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
"build",
|
|
||||||
"@href",
|
|
||||||
"@representation",
|
|
||||||
"minimal",
|
|
||||||
"cancel",
|
|
||||||
"id",
|
|
||||||
"state_change")
|
|
||||||
}
|
|
||||||
|
|
||||||
example { expect(sidekiq_payload).to be == {
|
example { expect(last_response.status).to be == 409 }
|
||||||
"id" => "#{build.id}",
|
example { expect(JSON.load(body)).to be == {
|
||||||
"user_id"=> repo.owner_id,
|
"@type" => "error",
|
||||||
"source" => "api"}
|
"error_type" => "build_not_cancelable",
|
||||||
}
|
"error_message" => "build is not running, cannot cancel"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
example { expect(Sidekiq::Client.last['queue']).to be == 'build_cancellations' }
|
describe "errored state" do
|
||||||
example { expect(Sidekiq::Client.last['class']).to be == 'Travis::Sidekiq::BuildCancellation' }
|
before { build.update_attribute(:state, "errored") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 409 }
|
||||||
|
example { expect(JSON.load(body)).to be == {
|
||||||
|
"@type" => "error",
|
||||||
|
"error_type" => "build_not_cancelable",
|
||||||
|
"error_message" => "build is not running, cannot cancel"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "failed state" do
|
||||||
|
before { build.update_attribute(:state, "failed") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 409 }
|
||||||
|
example { expect(JSON.load(body)).to be == {
|
||||||
|
"@type" => "error",
|
||||||
|
"error_type" => "build_not_cancelable",
|
||||||
|
"error_message" => "build is not running, cannot cancel"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "canceled state" do
|
||||||
|
before { build.update_attribute(:state, "canceled") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 409 }
|
||||||
|
example { expect(JSON.load(body)).to be == {
|
||||||
|
"@type" => "error",
|
||||||
|
"error_type" => "build_not_cancelable",
|
||||||
|
"error_message" => "build is not running, cannot cancel"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "existing repository, push access, cancelable" do
|
||||||
|
let(:params) {{}}
|
||||||
|
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
||||||
|
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
||||||
|
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
|
||||||
|
|
||||||
|
describe "started state" do
|
||||||
|
before { build.update_attribute(:state, "started") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 202 }
|
||||||
|
example { expect(JSON.load(body).to_s).to include(
|
||||||
|
"@type",
|
||||||
|
"build",
|
||||||
|
"@href",
|
||||||
|
"@representation",
|
||||||
|
"minimal",
|
||||||
|
"cancel",
|
||||||
|
"id",
|
||||||
|
"state_change")
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(sidekiq_payload).to be == {
|
||||||
|
"id" => "#{build.id}",
|
||||||
|
"user_id"=> repo.owner_id,
|
||||||
|
"source" => "api"}
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(Sidekiq::Client.last['queue']).to be == 'build_cancellations' }
|
||||||
|
example { expect(Sidekiq::Client.last['class']).to be == 'Travis::Sidekiq::BuildCancellation' }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "started queued" do
|
||||||
|
before { build.update_attribute(:state, "queued") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 202 }
|
||||||
|
example { expect(JSON.load(body).to_s).to include(
|
||||||
|
"@type",
|
||||||
|
"build",
|
||||||
|
"@href",
|
||||||
|
"@representation",
|
||||||
|
"minimal",
|
||||||
|
"cancel",
|
||||||
|
"id",
|
||||||
|
"state_change")
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(sidekiq_payload).to be == {
|
||||||
|
"id" => "#{build.id}",
|
||||||
|
"user_id"=> repo.owner_id,
|
||||||
|
"source" => "api"}
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(Sidekiq::Client.last['queue']).to be == 'build_cancellations' }
|
||||||
|
example { expect(Sidekiq::Client.last['class']).to be == 'Travis::Sidekiq::BuildCancellation' }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "received state" do
|
||||||
|
before { build.update_attribute(:state, "received") }
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
|
|
||||||
|
example { expect(last_response.status).to be == 202 }
|
||||||
|
example { expect(JSON.load(body).to_s).to include(
|
||||||
|
"@type",
|
||||||
|
"build",
|
||||||
|
"@href",
|
||||||
|
"@representation",
|
||||||
|
"minimal",
|
||||||
|
"cancel",
|
||||||
|
"id",
|
||||||
|
"state_change")
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(sidekiq_payload).to be == {
|
||||||
|
"id" => "#{build.id}",
|
||||||
|
"user_id"=> repo.owner_id,
|
||||||
|
"source" => "api"}
|
||||||
|
}
|
||||||
|
|
||||||
|
example { expect(Sidekiq::Client.last['queue']).to be == 'build_cancellations' }
|
||||||
|
example { expect(Sidekiq::Client.last['class']).to be == 'Travis::Sidekiq::BuildCancellation' }
|
||||||
|
end
|
||||||
|
|
||||||
describe "setting id has no effect" do
|
describe "setting id has no effect" do
|
||||||
let(:params) {{ id: 42 }}
|
let(:params) {{ id: 42 }}
|
||||||
|
before { post("/v3/build/#{build.id}/cancel", params, headers) }
|
||||||
example { expect(sidekiq_payload).to be == {
|
example { expect(sidekiq_payload).to be == {
|
||||||
"id" => "#{build.id}",
|
"id" => "#{build.id}",
|
||||||
"user_id"=> repo.owner_id,
|
"user_id"=> repo.owner_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user