fix specs for new structure
This commit is contained in:
parent
68ba4b9fce
commit
587ed37395
|
@ -1,19 +1,19 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Travis::API::V3::Services::Crons::Create do
|
describe Travis::API::V3::Services::Cron::Create do
|
||||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
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(: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(: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(: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(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
|
||||||
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}", "Content-Type" => "application/json" }}
|
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}", "Content-Type" => "application/json" }}
|
||||||
let(:options) {{ "tue" => true, "sat" => true, "sun" => false, "disable_by_push" => true, "hour" => 12 }}
|
let(:options) {{ "interval" => "monthly", "disable_by_build" => false }}
|
||||||
let(:parsed_body) { JSON.load(body) }
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
describe "creating a cron job" do
|
describe "creating a cron job" do
|
||||||
before { last_cron }
|
before { last_cron }
|
||||||
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/repo/#{repo.id}/branch/#{branch.name}/crons/create", options, headers) }
|
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/cron/create", options, headers) }
|
||||||
example { expect(current_cron == last_cron).to be_falsey }
|
example { expect(current_cron == last_cron).to be_falsey }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(parsed_body).to be == {
|
example { expect(parsed_body).to be == {
|
||||||
|
@ -36,20 +36,13 @@ describe Travis::API::V3::Services::Crons::Create do
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
"@representation" => "minimal",
|
"@representation" => "minimal",
|
||||||
"name" => "#{branch.name}" },
|
"name" => "#{branch.name}" },
|
||||||
"hour" => 12,
|
"interval" => "monthly",
|
||||||
"mon" => false,
|
"disable_by_build" => false
|
||||||
"tue" => true,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => true,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "try creating a cron job without login" do
|
describe "try creating a cron job without login" do
|
||||||
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create") }
|
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/cron/create", options) }
|
||||||
example { expect(parsed_body).to be == {
|
example { expect(parsed_body).to be == {
|
||||||
"@type" => "error",
|
"@type" => "error",
|
||||||
"error_type" => "login_required",
|
"error_type" => "login_required",
|
||||||
|
@ -59,7 +52,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
||||||
|
|
||||||
describe "try creating a cron job with a user without permissions" 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 { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
||||||
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/crons/create", {}, headers) }
|
before { post("/v3/repo/#{repo.id}/branch/#{branch.name}/cron/create", options, headers) }
|
||||||
example { expect(parsed_body).to be == {
|
example { expect(parsed_body).to be == {
|
||||||
"@type" => "error",
|
"@type" => "error",
|
||||||
"error_type" => "insufficient_access",
|
"error_type" => "insufficient_access",
|
||||||
|
@ -78,7 +71,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
||||||
|
|
||||||
describe "creating cron on a non-existing repository by slug" 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 { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
||||||
before { post("/v3/repo/svenfuchs%2Fminimal1/branch/master/crons/create", {}, headers) }
|
before { post("/v3/repo/svenfuchs%2Fminimal1/branch/master/cron/create", options, headers) }
|
||||||
example { expect(last_response).to be_not_found }
|
example { expect(last_response).to be_not_found }
|
||||||
example { expect(parsed_body).to be == {
|
example { expect(parsed_body).to be == {
|
||||||
"@type" => "error",
|
"@type" => "error",
|
||||||
|
@ -90,7 +83,7 @@ describe Travis::API::V3::Services::Crons::Create do
|
||||||
|
|
||||||
describe "creating cron on a non-existing branch" do
|
describe "creating cron on a non-existing branch" do
|
||||||
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, push: false) }
|
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) }
|
before { post("/v3/repo/#{repo.id}/branch/hopefullyNonExistingBranch/cron/create", options, headers) }
|
||||||
example { expect(last_response).to be_not_found }
|
example { expect(last_response).to be_not_found }
|
||||||
example { expect(parsed_body).to be == {
|
example { expect(parsed_body).to be == {
|
||||||
"@type" => "error",
|
"@type" => "error",
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Travis::API::V3::Services::Cron::Delete do
|
describe Travis::API::V3::Services::Cron::Delete do
|
||||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch, interval:'daily') }
|
||||||
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}" }}
|
||||||
let(:parsed_body) { JSON.load(body) }
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
@ -33,15 +33,8 @@ describe Travis::API::V3::Services::Cron::Delete do
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
"@representation" => "minimal",
|
"@representation" => "minimal",
|
||||||
"name" => branch.name },
|
"name" => branch.name },
|
||||||
"hour" => nil,
|
"interval" => "daily",
|
||||||
"mon" => false,
|
"disable_by_build" => true
|
||||||
"tue" => false,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => false,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Travis::API::V3::Services::Cron::Find do
|
describe Travis::API::V3::Services::Cron::Find do
|
||||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch, interval:'daily') }
|
||||||
let(:parsed_body) { JSON.load(body) }
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
describe "fetching a cron job by id" do
|
describe "fetching a cron job by id" do
|
||||||
|
@ -29,15 +29,8 @@ describe Travis::API::V3::Services::Cron::Find do
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
"@representation" => "minimal",
|
"@representation" => "minimal",
|
||||||
"name" => branch.name },
|
"name" => branch.name },
|
||||||
"hour" => nil,
|
"interval" => "daily",
|
||||||
"mon" => false,
|
"disable_by_build" => true
|
||||||
"tue" => false,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => false,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,15 +86,8 @@ describe Travis::API::V3::Services::Cron::Find do
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
"@representation" => "minimal",
|
"@representation" => "minimal",
|
||||||
"name" => branch.name },
|
"name" => branch.name },
|
||||||
"hour" => nil,
|
"interval" => "daily",
|
||||||
"mon" => false,
|
"disable_by_build" => true
|
||||||
"tue" => false,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => false,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
73
spec/v3/services/cron/for_branch_spec.rb
Normal file
73
spec/v3/services/cron/for_branch_spec.rb
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::API::V3::Services::Cron::ForBranch 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, interval:'daily') }
|
||||||
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
|
describe "fetching all crons by repo id" do
|
||||||
|
before { cron }
|
||||||
|
before { get("/v3/repo/#{repo.id}/branch/#{branch.name}/cron") }
|
||||||
|
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" },
|
||||||
|
"branch" => {
|
||||||
|
"@type" => "branch",
|
||||||
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
|
"@representation" => "minimal",
|
||||||
|
"name" => branch.name },
|
||||||
|
"interval" => "daily",
|
||||||
|
"disable_by_build" => true
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "fetching crons on a non-existing repository by slug" do
|
||||||
|
before { get("/v3/repo/svenfuchs%2Fminimal1/branch/master/cron") }
|
||||||
|
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 on a non-existing branch" do
|
||||||
|
before { get("/v3/repo/#{repo.id}/branch/hopefullyNonExistingBranch/cron") }
|
||||||
|
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}/branch/#{branch.name}/cron") }
|
||||||
|
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
|
|
@ -1,103 +0,0 @@
|
||||||
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(: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}/branch/#{branch.name}/crons") }
|
|
||||||
example { expect(last_response).to be_ok }
|
|
||||||
example { expect(parsed_body).to be == {
|
|
||||||
"@type" => "crons",
|
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}/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}/branch/#{branch.name}/crons",
|
|
||||||
"offset" => 0,
|
|
||||||
"limit" => 25},
|
|
||||||
"last" => {
|
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}/crons",
|
|
||||||
"offset" => 0,
|
|
||||||
"limit" => 25 }},
|
|
||||||
"crons" => [
|
|
||||||
{
|
|
||||||
"@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" },
|
|
||||||
"branch" => {
|
|
||||||
"@type" => "branch",
|
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
|
||||||
"@representation" => "minimal",
|
|
||||||
"name" => "#{branch.name}" },
|
|
||||||
"hour" => nil,
|
|
||||||
"mon" => false,
|
|
||||||
"tue" => false,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => false,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}}
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "fetching crons on a non-existing repository by slug" do
|
|
||||||
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",
|
|
||||||
"error_type" => "not_found",
|
|
||||||
"error_message" => "repository not found (or insufficient access)",
|
|
||||||
"resource_type" => "repository"
|
|
||||||
}}
|
|
||||||
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}/branch/#{branch.name}/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
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Travis::API::V3::Services::Crons::ForRepository do
|
describe Travis::API::V3::Services::Crons::ForRepository do
|
||||||
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
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(:branch) { Travis::API::V3::Models::Branch.where(repository_id: repo).first }
|
||||||
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch) }
|
let(:cron) { Travis::API::V3::Models::Cron.create(branch: branch, interval:'daily') }
|
||||||
let(:parsed_body) { JSON.load(body) }
|
let(:parsed_body) { JSON.load(body) }
|
||||||
|
|
||||||
describe "fetching all crons by repo id" do
|
describe "fetching all crons by repo id" do
|
||||||
|
@ -51,15 +51,8 @@ describe Travis::API::V3::Services::Crons::ForRepository do
|
||||||
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
"@href" => "/v3/repo/#{repo.id}/branch/#{branch.name}",
|
||||||
"@representation" => "minimal",
|
"@representation" => "minimal",
|
||||||
"name" => "#{branch.name}" },
|
"name" => "#{branch.name}" },
|
||||||
"hour" => nil,
|
"interval" => "daily",
|
||||||
"mon" => false,
|
"disable_by_build" => true
|
||||||
"tue" => false,
|
|
||||||
"wed" => false,
|
|
||||||
"thu" => false,
|
|
||||||
"fri" => false,
|
|
||||||
"sat" => false,
|
|
||||||
"sun" => false,
|
|
||||||
"disable_by_push" => true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user