-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from alphagov/suspended-user-check
Check if requester is suspended before creating Zendesk ticket
- Loading branch information
Showing
4 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
require "rails_helper" | ||
|
||
describe SupportTicket, "validations" do | ||
let(:required_atrributes) do | ||
{ | ||
subject: "Feedback for app", | ||
description: "Ticket details go here.", | ||
} | ||
end | ||
|
||
it "validates presence of subject" do | ||
support_ticket = described_class.new({}) | ||
support_ticket.valid? | ||
|
@@ -14,6 +21,59 @@ | |
|
||
expect(support_ticket.errors.messages.to_h).to include(description: include("can't be blank")) | ||
end | ||
|
||
describe "#requester_not_suspended validation" do | ||
it "is invalid if requester is suspended in Zendesk" do | ||
zendesk_has_suspended_user_with_email("[email protected]") | ||
|
||
support_ticket = described_class.new( | ||
required_atrributes.merge( | ||
requester: { "locale_id" => 1, email: "[email protected]", "name" => "Naughtly user" }, | ||
), | ||
) | ||
support_ticket.valid? | ||
|
||
expect(support_ticket.errors.messages.to_h).to include(requester: include("is suspended in Zendesk")) | ||
end | ||
|
||
it "is valid if requester is not suspended in Zendesk" do | ||
zendesk_has_valid_user_with_email("[email protected]") | ||
|
||
support_ticket = described_class.new( | ||
required_atrributes.merge( | ||
{ requester: { email: "[email protected]" } }, | ||
), | ||
) | ||
expect(support_ticket.valid?).to eq(true) | ||
end | ||
|
||
it "is valid if Zendesk doesn't have user with this email address" do | ||
zendesk_has_no_user_with_email("[email protected]") | ||
|
||
support_ticket = described_class.new( | ||
required_atrributes.merge( | ||
{ requester: { "email" => "[email protected]", "name" => "User" } }, | ||
), | ||
) | ||
|
||
expect(support_ticket.valid?).to eq(true) | ||
end | ||
|
||
it "doesn't validate if requester attribute is not provided" do | ||
support_ticket = described_class.new(required_atrributes) | ||
|
||
expect(support_ticket.valid?).to eq(true) | ||
end | ||
|
||
it "doesn't validate if requester email attribute is not provided" do | ||
support_ticket = described_class.new( | ||
required_atrributes.merge( | ||
{ requester: { "name" => "Some app" } }, | ||
), | ||
) | ||
expect(support_ticket.valid?).to eq(true) | ||
end | ||
end | ||
end | ||
|
||
describe SupportTicket, "#zendesk_ticket_attributes" do | ||
|
@@ -22,7 +82,7 @@ | |
subject: "Feedback for app", | ||
description: "Ticket details go here.", | ||
priority: "normal", | ||
requester: { "locale_id" => 1, "email" => "someone@exampe.com", "name" => "Some user" }, | ||
requester: { "locale_id" => 1, "email" => "someone@example.com", "name" => "Some user" }, | ||
collaborators: %w[[email protected] [email protected]], | ||
tags: %w[app_name], | ||
custom_fields: [ | ||
|
@@ -38,7 +98,7 @@ | |
"body" => "Ticket details go here.", | ||
}, | ||
"priority" => "normal", | ||
"requester" => { "locale_id" => 1, "email" => "someone@exampe.com", "name" => "Some user" }, | ||
"requester" => { "locale_id" => 1, "email" => "someone@example.com", "name" => "Some user" }, | ||
"collaborators" => %w[[email protected] [email protected]], | ||
"tags" => %w[app_name], | ||
"custom_fields" => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,15 @@ | |
describe "Support Tickets" do | ||
it "responds succesfully" do | ||
stub_zendesk_ticket_creation | ||
zendesk_has_valid_user_with_email("[email protected]") | ||
|
||
post "/support-tickets", | ||
params: { | ||
subject: "Feedback for app", | ||
tags: %w[app_name], | ||
description: "Ticket details go here.", | ||
priority: "normal", | ||
requester: { locale_id: 1, email: "someone@exampe.com", name: "Some user" }, | ||
requester: { locale_id: 1, email: "someone@example.com", name: "Some user" }, | ||
collaborators: %w[[email protected] [email protected]], | ||
custom_fields: [ | ||
{ id: 7_948_652_819_356, value: "cr_inaccuracy" }, | ||
|
@@ -24,6 +25,7 @@ | |
end | ||
|
||
it "sends the feedback to Zendesk" do | ||
zendesk_has_valid_user_with_email("[email protected]") | ||
zendesk_request = expect_zendesk_to_receive_ticket( | ||
"subject" => "Feedback for app", | ||
"tags" => %w[app_name], | ||
|
@@ -36,7 +38,7 @@ | |
params: { | ||
subject: "Feedback for app", | ||
tags: %w[app_name], | ||
requester: { locale_id: 1, email: "someone@exampe.com", name: "Some user" }, | ||
requester: { locale_id: 1, email: "someone@example.com", name: "Some user" }, | ||
description: "Ticket details go here.", | ||
} | ||
|
||
|