Repository URL to install this package:
|
Version:
2.23.0 ▾
|
require 'spec_helper'
describe JPlatform::Ticket, :type => :model do
ticket = nil
before(:each) do
stub_get("/api/v1/tickets/114.json").to_return(body: fixture("single_ticket_from_index_without_includes.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/tickets/1.json").to_return(body: fixture("ticket.json"), headers: {content_type: "application/json; charset=utf-8"})
ticket = JPlatform::Ticket.find(1)
end
describe "dropdown_arr" do
it "converts an Hash into an Array for our dropdowns" do
test_hash = {insignificant: 1, important: 9}
results = JPlatform::Ticket.dropdown_arr(test_hash)
result_for_insignificant = results.first
expect(result_for_insignificant).to eq(['insignificant'.titleize, 'insignificant'])
end
end
describe "statuses" do
it "exposes the statuses required" do
expect(JPlatform::Ticket::STATUSES.keys).to include :new, :in_progress, :resolved
titleized_statuses = JPlatform::Ticket.statuses.map(&:first)
expect(titleized_statuses).to include 'New', 'In Progress', 'Resolved'
end
# For the edit dropdowns
describe "select_statuses" do
it "exposes the statuses except for Resolved" do
titleized_selection_statuses = JPlatform::Ticket.select_statuses.map(&:first)
expect(titleized_selection_statuses).to include 'New', 'In Progress'
expect(titleized_selection_statuses).to_not include 'Resolved'
end
end
end
it "returns created_at as a Time" do
expect(ticket.created_at.is_a?(Time)).to be_truthy
end
it "returns updated_at as a Time" do
expect(ticket.updated_at.is_a?(Time)).to be_truthy
end
it "returns true for is_overdue? when it's overdue" do
expect(ticket.is_overdue?).to be_truthy
end
it "returns true for is_\#{status}? for each status" do
ticket = JPlatform::Ticket.new
ticket.status_cd = 1
expect(ticket.is_new?).to be_truthy
expect(ticket.is_in_progress?).to be_falsey
expect(ticket.is_resolved?).to be_falsey
ticket.status_cd = 5
expect(ticket.is_new?).to be_falsey
expect(ticket.is_in_progress?).to be_truthy
expect(ticket.is_resolved?).to be_falsey
ticket.status_cd = 9
expect(ticket.is_new?).to be_falsey
expect(ticket.is_in_progress?).to be_falsey
expect(ticket.is_resolved?).to be_truthy
end
it "returns true for high_priority? when it is high priority" do
expect(ticket.high_priority?).to be_truthy
end
it "returns true for has_new_status? when its status is new" do
expect(ticket.has_new_status?).to be_truthy
end
context "When the ticket is retrieved without including related entities" do
it "returns creator full name" do
ticket = JPlatform::Ticket.find(114)
expect(ticket.creator_full_name).to eq("Jugnoo Dev 1")
end
it "returns assignee full name" do
ticket = JPlatform::Ticket.find(114)
expect(ticket.assignee_full_name).to eq("Jugnoo Dev 2")
end
it "returns social message type" do
ticket = JPlatform::Ticket.find(114)
expect(ticket.social_message_type).to eq("SocialMessage::TwitterTweet")
end
it "returns social message author name" do
ticket = JPlatform::Ticket.find(114)
expect(ticket.social_message_author_name).to eq("Jaspersoft Corp.")
end
end
context "When the ticket is retrieved including related entities" do
it "returns creator full name" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.creator_full_name).to eq(ticket.creator.full_name)
end
it "returns assignee full name" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.assignee_full_name).to eq(ticket.assignee.full_name)
end
it "returns social message type" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.social_message_type).to eq(ticket.social_message.type)
end
it "returns social message author name" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.social_message_author_name).to eq(ticket.social_message.author.to_s)
end
it "returns the social message string if when rendering the ticket as a string" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.to_s).to eq(ticket.social_message.to_s)
end
it "returns the default reply social message" do
ticket = JPlatform::Ticket.find(1)
expect(ticket.default_reply_text).to eq(ticket.reply_to_author_name + " ")
end
end
it "returns customer_name from social_message" do
expect(ticket.customer_name).to eq("Toy Story Teller")
end
it "returns customer_name as nil from social_message if ticket is not yet associated with a social message" do
ticket.social_message = nil
expect(ticket.customer_name).to eq(nil)
end
it "returns true for is_assigned? when when ticket is assigned to a user" do
expect(ticket.is_assigned?).to be_truthy
end
it "returns true for is_assigned_to(user) when when ticket is assigned to the specific user" do
stub_get("/api/v1/users/1.json").to_return(body: fixture("user1.json"), headers: {content_type: "application/json; charset=utf-8"})
user = JPlatform::User.find(1)
expect(ticket.is_assigned_to(user)).to be_truthy
end
it "returns social_message's text when calling message" do
expect(ticket.message).to eq("This plastic toy is designed so badly. http://www.google.com/?toy=bad")
end
it "returns social_message's text when ticket is rendered as a string" do
expect(ticket.to_s).to eq("This plastic toy is designed so badly. http://www.google.com/?toy=bad")
end
it "returns nil for social_message's text when calling message if ticket is not yet associated to a social message" do
ticket.social_message = nil
expect(ticket.message).to eq(nil)
end
it "returns nil for social_message's text when ticket is rendered as a string if ticket is not yet associated to a social message" do
ticket.social_message = nil
expect(ticket.to_s).to eq(nil)
end
describe "#resolution" do
context "when not set (i.e.) new / in-progress" do
it "returns resolution as nil" do
expect(ticket.resolution).to be_nil
end
end
context "when set (i.e. resolved)" do
it "returns resolution" do
stub_get("/api/v1/tickets/5.json").to_return(body: fixture("ticket_resolved.json"), headers: {content_type: "application/json; charset=utf-8"})
ticket = JPlatform::Ticket.find(5)
expect(ticket.resolution.to_s).to_not be_nil
end
end
end
describe "#due_on" do
context "when not set" do
it "returns due_on as nil" do
stub_get("/api/v1/tickets/5.json").to_return(body: fixture("ticket_resolved.json"), headers: {content_type: "application/json; charset=utf-8"})
ticket = JPlatform::Ticket.find(5)
expect(ticket.due_on).to be_nil
end
end
context "when set" do
it "returns due_on as date" do
expect(ticket.due_on.is_a?(Date)).to be_truthy
end
end
end
describe "network" do
it "delegates network to social message" do
expect(ticket.network).to eq(ticket.social_message.network)
end
end
end