fix and add tests for crons
This commit is contained in:
parent
aca632ed15
commit
75449baacd
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe Travis::API::V3::Services::Cron::Delete 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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
||||
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
||||
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
||||
let(:parsed_body) { JSON.load(body) }
|
||||
|
@ -20,6 +21,11 @@ describe Travis::API::V3::Services::Cron::Delete do
|
|||
"read" => true,
|
||||
"delete" => true },
|
||||
"id" => cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => branch.name },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
@ -52,7 +58,7 @@ describe Travis::API::V3::Services::Cron::Delete do
|
|||
"permission" => "delete",
|
||||
"cron" => {
|
||||
"@type" => "cron",
|
||||
"@href" => "/v3/cron/#{cron.id}",
|
||||
"@href" => "/cron/#{cron.id}", # should be /v3/cron/#{cron.id}
|
||||
"@representation" => "minimal",
|
||||
"id" => cron.id }
|
||||
}}
|
||||
|
|
|
@ -2,7 +2,8 @@ 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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
||||
let(:parsed_body) { JSON.load(body) }
|
||||
|
||||
describe "fetching a cron job by id" do
|
||||
|
@ -16,6 +17,11 @@ describe Travis::API::V3::Services::Cron::Find do
|
|||
"read" => true,
|
||||
"delete" => false },
|
||||
"id" => cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => branch.name },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
@ -66,6 +72,11 @@ describe Travis::API::V3::Services::Cron::Find do
|
|||
"read" => true,
|
||||
"delete" => false },
|
||||
"id" => cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => branch.name },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
|
|
@ -2,8 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe Travis::API::V3::Services::Crons::Create do
|
||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
||||
let(:last_cron) {Travis::API::V3::Models::Cron.where(repository_id: repo.id).last}
|
||||
let(:current_cron) {Travis::API::V3::Models::Cron.where(repository_id: repo.id).last}
|
||||
let(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||
let(:last_cron) {Travis::API::V3::Models::Cron.where(branch_id: branch.id).last}
|
||||
let(:current_cron) {Travis::API::V3::Models::Cron.where(branch_id: branch.id).last}
|
||||
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
||||
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
|
||||
let(:parsed_body) { JSON.load(body) }
|
||||
|
@ -11,7 +12,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
describe "creating a cron job" do
|
||||
before { last_cron }
|
||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: true) }
|
||||
before { post("/v3/repo/#{repo.id}/crons/create", {}, headers) }
|
||||
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create", {}, headers) }
|
||||
example { expect(current_cron == last_cron).to be_falsey }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(parsed_body).to be == {
|
||||
|
@ -22,6 +23,11 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
"read" => true,
|
||||
"delete" => true },
|
||||
"id" => current_cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => "#{branch.name}" },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
|
@ -33,7 +39,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
end
|
||||
|
||||
describe "try creating a cron job without login" do
|
||||
before { post("/v3/repo/#{repo.id}/crons/create") }
|
||||
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create") }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
"error_type" => "login_required",
|
||||
|
@ -43,7 +49,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
|
||||
describe "try creating a cron job with a user without permissions" do
|
||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
||||
before { post("/v3/repo/#{repo.id}/crons/create", {}, headers) }
|
||||
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create", {}, headers) }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
"error_type" => "insufficient_access",
|
||||
|
@ -52,7 +58,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
"permission" => "create_cron",
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
"@href" => "/repo/#{repo.id}", # should be /v3/repo/#{repo.id}
|
||||
"@representation" => "minimal",
|
||||
"id" => repo.id,
|
||||
"name" => "minimal",
|
||||
|
@ -62,7 +68,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
|
||||
describe "creating cron on a non-existing repository by slug" do
|
||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
||||
before { post("/v3/repo/svenfuchs%2Fminimal1/crons/create", {}, headers) }
|
||||
before { post("/v3/repo/svenfuchs%2Fminimal1/branch/master/crons/create", {}, headers) }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
|
@ -72,4 +78,16 @@ describe Travis::API::V3::Services::Crons::Create do
|
|||
}}
|
||||
end
|
||||
|
||||
describe "creating cron on a non-existing branch" do
|
||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
||||
before { post("/v3/repo/#{repo.id}/branch/hopefullyNonExistingBranch/crons/create", {}, headers) }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
"error_type" => "not_found",
|
||||
"error_message" => "branch not found (or insufficient access)",
|
||||
"resource_type" => "branch"
|
||||
}}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,38 +2,62 @@ require 'spec_helper'
|
|||
|
||||
describe Travis::API::V3::Services::Crons::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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
||||
let(:parsed_body) { JSON.load(body) }
|
||||
|
||||
describe "fetching all crons by repo id" do
|
||||
before { get("/v3/repo/#{repo.id}/crons") }
|
||||
before { cron }
|
||||
before { get("/v3/repo/#{repo.id}/branch/#{branch.name}/crons") }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "crons",
|
||||
"@href" => "/v3/repo/#{repo.id}/crons",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}/crons",
|
||||
"@representation" => "standard",
|
||||
"@pagination" => {
|
||||
"limit" => 25,
|
||||
"offset" => 0,
|
||||
"count" => 0,
|
||||
"count" => 1,
|
||||
"is_first" => true,
|
||||
"is_last" => true,
|
||||
"next" => nil,
|
||||
"prev" => nil,
|
||||
"first" => {
|
||||
"@href" => "/v3/repo/#{repo.id}/crons",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}/crons",
|
||||
"offset" => 0,
|
||||
"limit" => 25},
|
||||
"last" => {
|
||||
"@href" => "/v3/repo/#{repo.id}/crons?limit=25&offset=-25",
|
||||
"offset" => -25,
|
||||
"last" => {
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}/crons",
|
||||
"offset" => 0,
|
||||
"limit" => 25 }},
|
||||
"crons" => []
|
||||
"crons" => [
|
||||
{
|
||||
"@type" => "cron",
|
||||
"@href" => "/v3/cron/#{cron.id}",
|
||||
"@representation" => "standard",
|
||||
"@permissions" => {
|
||||
"read" => true,
|
||||
"delete" => false },
|
||||
"id" => cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => "#{branch.name}" },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
"@representation" => "minimal",
|
||||
"id" => repo.id,
|
||||
"name" => "minimal",
|
||||
"slug" => "svenfuchs/minimal" }
|
||||
}
|
||||
]
|
||||
}}
|
||||
end
|
||||
|
||||
describe "fetching crons on a non-existing repository by slug" do
|
||||
before { get("/v3/repo/svenfuchs%2Fminimal1/crons") }
|
||||
before { get("/v3/repo/svenfuchs%2Fminimal1/branch/master/crons") }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
|
@ -43,9 +67,20 @@ describe Travis::API::V3::Services::Crons::Find do
|
|||
}}
|
||||
end
|
||||
|
||||
describe "fetching crons on a non-existing branch" do
|
||||
before { get("/v3/repo/#{repo.id}/branch/hopefullyNonExistingBranch/crons") }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
"error_type" => "not_found",
|
||||
"error_message" => "branch not found (or insufficient access)",
|
||||
"resource_type" => "branch"
|
||||
}}
|
||||
end
|
||||
|
||||
describe "fetching crons from private repo, not authenticated" do
|
||||
before { repo.update_attribute(:private, true) }
|
||||
before { get("/v3/repo/#{repo.id}/crons") }
|
||||
before { get("/v3/repo/#{repo.id}/branch/#{branch.name}/crons") }
|
||||
after { repo.update_attribute(:private, false) }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
|
|
83
spec/v3/services/crons/for_repository_spec.rb
Normal file
83
spec/v3/services/crons/for_repository_spec.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::API::V3::Services::Crons::ForRepository do
|
||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
||||
let(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
||||
let(:parsed_body) { JSON.load(body) }
|
||||
|
||||
describe "fetching all crons by repo id" do
|
||||
before { cron }
|
||||
before { get("/v3/repo/#{repo.id}/crons") }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "crons",
|
||||
"@href" => "/v3/repo/#{repo.id}/crons",
|
||||
"@representation" => "standard",
|
||||
"@pagination" => {
|
||||
"limit" => 25,
|
||||
"offset" => 0,
|
||||
"count" => 1,
|
||||
"is_first" => true,
|
||||
"is_last" => true,
|
||||
"next" => nil,
|
||||
"prev" => nil,
|
||||
"first" => {
|
||||
"@href" => "/v3/repo/#{repo.id}/crons",
|
||||
"offset" => 0,
|
||||
"limit" => 25},
|
||||
"last" => {
|
||||
"@href" => "/v3/repo/#{repo.id}/crons",
|
||||
"offset" => 0,
|
||||
"limit" => 25 }},
|
||||
"crons" => [
|
||||
{
|
||||
"@type" => "cron",
|
||||
"@href" => "/v3/cron/#{cron.id}",
|
||||
"@representation" => "standard",
|
||||
"@permissions" => {
|
||||
"read" => true,
|
||||
"delete" => false },
|
||||
"id" => cron.id,
|
||||
"branch" => {
|
||||
"@type" => "branch",
|
||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||
"@representation" => "minimal",
|
||||
"name" => "#{branch.name}" },
|
||||
"repository" => {
|
||||
"@type" => "repository",
|
||||
"@href" => "/v3/repo/#{repo.id}",
|
||||
"@representation" => "minimal",
|
||||
"id" => repo.id,
|
||||
"name" => "minimal",
|
||||
"slug" => "svenfuchs/minimal" }
|
||||
}
|
||||
]
|
||||
}}
|
||||
end
|
||||
|
||||
describe "fetching crons on a non-existing repository by slug" do
|
||||
before { get("/v3/repo/svenfuchs%2Fminimal1/crons") }
|
||||
example { expect(last_response).to be_not_found }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "error",
|
||||
"error_type" => "not_found",
|
||||
"error_message" => "repository not found (or insufficient access)",
|
||||
"resource_type" => "repository"
|
||||
}}
|
||||
end
|
||||
|
||||
describe "fetching crons from private repo, not authenticated" do
|
||||
before { repo.update_attribute(:private, true) }
|
||||
before { get("/v3/repo/#{repo.id}/crons") }
|
||||
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" => "repository not found (or insufficient access)",
|
||||
"resource_type" => "repository"
|
||||
}}
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user