add spec for broadcasts
This commit is contained in:
parent
28c6e04eb8
commit
907591e001
|
@ -1,41 +1,79 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Travis::API::V3::Services::Broadcasts::ForCurrentUser do
|
describe Travis::API::V3::Services::Broadcasts::ForCurrentUser do
|
||||||
let(:user) { Travis::API::V3::Models::User.where(login: 'svenfuchs').first }
|
let(:repo) { Travis::API::V3::Models::Repository.where(owner_name: 'svenfuchs', name: 'minimal').first }
|
||||||
let(:broadcast) { Travis::API::V3::Models::Broadcast.where(recipient_id: user.id) }
|
# let(:user) { Travis::API::V3::Models::User.where(login: 'svenfuchs') }
|
||||||
|
|
||||||
let(:token) { Travis::Api::App::AccessToken.create(user: user, 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(user: user, pull: true) }
|
|
||||||
# before { Travis::API::V3::Models::Broadcast.create(recipient_id: repo.id, recipient_type: "Organization", message: "This is a test!") }
|
|
||||||
# before { repo.update_attribute(:private, true) }
|
|
||||||
# after { repo.update_attribute(:private, false) }
|
|
||||||
|
|
||||||
# let(:org) { Travis::API::V3::Models::Organization.new(login: 'example-org') }
|
before { Travis::API::V3::Models::Permission.create(user: repo.owner, pull: true) }
|
||||||
# before { org.save! }
|
before { repo.update_attribute(:private, true) }
|
||||||
# before { org.memberships.create(user: user.login) }
|
after { repo.update_attribute(:private, false) }
|
||||||
# after { org.delete }
|
|
||||||
|
let(:org) { Travis::API::V3::Models::Organization.new(login: 'example-org') }
|
||||||
|
before { org.save! }
|
||||||
|
before { org.memberships.create(user: repo.owner) }
|
||||||
|
after { org.delete }
|
||||||
|
|
||||||
|
before { Travis::API::V3::Models::Broadcast.create(recipient_id: repo.id, recipient_type: "Repository", message: "Repository broadcast!", created_at: "2010-11-12T13:00:00Z", updated_at: "2010-11-12T13:00:00Z") }
|
||||||
|
before { Travis::API::V3::Models::Broadcast.create(recipient_id: org.id, recipient_type: "Organization", message: "Organization broadcast!", created_at: "2010-11-12T13:00:00Z", updated_at: "2010-11-12T13:00:00Z") }
|
||||||
|
before { Travis::API::V3::Models::Broadcast.create(recipient_id: repo.owner_id, recipient_type: "User", message: "User broadcast!", created_at: "2010-11-12T13:00:00Z", updated_at: "2010-11-12T13:00:00Z") }
|
||||||
|
before { Travis::API::V3::Models::Broadcast.create(recipient_id: nil, recipient_type: nil, message: "Global broadcast!", created_at: "2010-11-12T13:00:00Z", updated_at: "2010-11-12T13:00:00Z") }
|
||||||
|
let(:broadcasts){ Travis::API::V3::Models::Broadcast.where(recipient_id: [repo.id, org.id, repo.owner_id, nil]) }
|
||||||
|
|
||||||
|
|
||||||
describe "authenticated as user with access" do
|
describe "authenticated as user with access" do
|
||||||
before { get("/v3/broadcasts", {}, headers) }
|
before { get("/v3/broadcasts", {}, headers) }
|
||||||
example { expect(last_response).to be_ok }
|
example { expect(last_response).to be_ok }
|
||||||
example { expect(JSON.load(body)).to be == {
|
example { expect(JSON.load(body)).to be == {
|
||||||
"@type" => "broadcasts",
|
"@type" => "broadcasts",
|
||||||
"@href" => "/v3/broadcasts",
|
"@href" => "/v3/broadcasts",
|
||||||
"@representation" => "standard",
|
"@representation" => "standard",
|
||||||
"broadcasts" => [{
|
"broadcasts" => [{
|
||||||
"@type" => "broadcast",
|
"@type" => "broadcast",
|
||||||
"@representation" => "standard",
|
"@representation"=>"standard",
|
||||||
"@permissions" => { "read"=>true, "sync"=>true },
|
"id" => broadcasts[0].id,
|
||||||
"id" => broadcasts[0].id,
|
"recipient_id" => broadcasts[0].recipient_id,
|
||||||
"recipient_id" => broadcasts[0].recipient_id,
|
"recipient_type" => broadcasts[0].recipient_type,
|
||||||
"recipient_type" => broadcasts[0].recipient_type,
|
"kind" => nil,
|
||||||
"kind" => broadcast[0].kind,
|
"message" => broadcasts[0].message,
|
||||||
"message" => broadcast[0].message,
|
"expired" => nil,
|
||||||
"expired" => nil,
|
"created_at" => "2010-11-12T13:00:00Z",
|
||||||
"created_at" => "2015-09-10T11:05:21Z",
|
"updated_at" => "2010-11-12T13:00:00Z" },
|
||||||
"updated_at" => "2015-09-10T11:05:21Z"
|
{
|
||||||
}]
|
"@type" => "broadcast",
|
||||||
|
"@representation"=> "standard",
|
||||||
|
"id" => broadcasts[1].id,
|
||||||
|
"recipient_id" => broadcasts[1].recipient_id,
|
||||||
|
"recipient_type" => broadcasts[1].recipient_type,
|
||||||
|
"kind" => nil,
|
||||||
|
"message" => broadcasts[1].message,
|
||||||
|
"expired" => nil,
|
||||||
|
"created_at" => "2010-11-12T13:00:00Z",
|
||||||
|
"updated_at" => "2010-11-12T13:00:00Z"},
|
||||||
|
{
|
||||||
|
"@type" => "broadcast",
|
||||||
|
"@representation"=> "standard",
|
||||||
|
"id" => broadcasts[2].id,
|
||||||
|
"recipient_id" => broadcasts[2].recipient_id,
|
||||||
|
"recipient_type" => broadcasts[2].recipient_type,
|
||||||
|
"kind" => nil,
|
||||||
|
"message" => broadcasts[2].message,
|
||||||
|
"expired" => nil,
|
||||||
|
"created_at" => "2010-11-12T13:00:00Z",
|
||||||
|
"updated_at" => "2010-11-12T13:00:00Z"},
|
||||||
|
{
|
||||||
|
"@type" => "broadcast",
|
||||||
|
"@representation"=> "standard",
|
||||||
|
"id" => broadcasts[3].id,
|
||||||
|
"recipient_id" => broadcasts[3].recipient_id,
|
||||||
|
"recipient_type" => broadcasts[3].recipient_type,
|
||||||
|
"kind" => nil,
|
||||||
|
"message" => broadcasts[3].message,
|
||||||
|
"expired" => nil,
|
||||||
|
"created_at" => "2010-11-12T13:00:00Z",
|
||||||
|
"updated_at" => "2010-11-12T13:00:00Z"}]
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user