add test for /cron/{cron.id} endpoint
This commit is contained in:
parent
a2a4737099
commit
f5f4b3b0b1
79
spec/v3/services/cron/find_spec.rb
Normal file
79
spec/v3/services/cron/find_spec.rb
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::API::V3::Services::Cron::Find do
|
||||||
|
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
||||||
|
let(:cron) { Travis::API::V3::Models::Cron.create(repository: repo) }
|
||||||
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
|
describe "fetching a cron job by id" do
|
||||||
|
before { get("/v3/cron/#{cron.id}") }
|
||||||
|
example { expect(last_response).to be_ok }
|
||||||
|
example { expect(parsed_body).to be == {
|
||||||
|
"@type" => "cron",
|
||||||
|
"@href" => "/v3/cron/#{cron.id}",
|
||||||
|
"@representation" => "standard",
|
||||||
|
"@permissions" => {
|
||||||
|
"read" => true,
|
||||||
|
"delete" => false },
|
||||||
|
"id" => cron.id,
|
||||||
|
"repository" => {
|
||||||
|
"@type" => "repository",
|
||||||
|
"@href" => "/v3/repo/#{repo.id}",
|
||||||
|
"@representation" => "minimal",
|
||||||
|
"id" => repo.id,
|
||||||
|
"name" => "minimal",
|
||||||
|
"slug" => "svenfuchs/minimal" }
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "fetching a non-existing cron job by id" do
|
||||||
|
before { get("/v3/cron/999999999999999") }
|
||||||
|
example { expect(last_response).to be_not_found }
|
||||||
|
example { expect(parsed_body).to be == {
|
||||||
|
"@type" => "error",
|
||||||
|
"error_type" => "not_found",
|
||||||
|
"error_message" => "cron not found (or insufficient access)",
|
||||||
|
"resource_type" => "cron"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "private cron, not authenticated" do
|
||||||
|
before { repo.update_attribute(:private, true) }
|
||||||
|
before { get("/v3/cron/#{cron.id}") }
|
||||||
|
after { repo.update_attribute(:private, false) }
|
||||||
|
example { expect(last_response).to be_not_found }
|
||||||
|
example { expect(parsed_body).to be == {
|
||||||
|
"@type" => "error",
|
||||||
|
"error_type" => "not_found",
|
||||||
|
"error_message" => "cron not found (or insufficient access)",
|
||||||
|
"resource_type" => "cron"
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "private cron, authenticated as user with access" do
|
||||||
|
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, pull: true) }
|
||||||
|
before { repo.update_attribute(:private, true) }
|
||||||
|
before { get("/v3/cron/#{cron.id}", {}, headers) }
|
||||||
|
after { repo.update_attribute(:private, false) }
|
||||||
|
example { expect(last_response).to be_ok }
|
||||||
|
example { expect(parsed_body).to be == {
|
||||||
|
"@type" => "cron",
|
||||||
|
"@href" => "/v3/cron/#{cron.id}",
|
||||||
|
"@representation" => "standard",
|
||||||
|
"@permissions" => {
|
||||||
|
"read" => true,
|
||||||
|
"delete" => false },
|
||||||
|
"id" => cron.id,
|
||||||
|
"repository" => {
|
||||||
|
"@type" => "repository",
|
||||||
|
"@href" => "/v3/repo/#{repo.id}",
|
||||||
|
"@representation" => "minimal",
|
||||||
|
"id" => repo.id,
|
||||||
|
"name" => "minimal",
|
||||||
|
"slug" => "svenfuchs/minimal" }
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user