-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AO3-6232 Include IP, referer, skin in support tickets (#4869)
* AO3-6232 Include IP, referer, skin in support tickets * Whoopses * Extract current_skin helper * Cleanup * Revert "Cleanup" This reverts commit 5f256af. * Review feedback * Better handling for empty referer * Fix more tests * Undo field rename
- Loading branch information
1 parent
d625107
commit 6a471a1
Showing
11 changed files
with
301 additions
and
38 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
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
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe FeedbacksController do | ||
include LoginMacros | ||
|
||
describe "POST #create" do | ||
let(:mock_zoho) { instance_double(ZohoResourceClient) } | ||
|
||
let(:default_parameters) do | ||
{ | ||
feedback: { | ||
comment: "Hello", | ||
email: "[email protected]", | ||
summary: "Summary", | ||
language: "en" | ||
} | ||
} | ||
end | ||
|
||
before do | ||
allow_any_instance_of(Feedback).to receive(:zoho_enabled?).and_return(true) | ||
allow(mock_zoho).to receive(:retrieve_contact_id) | ||
allow_any_instance_of(FeedbackReporter).to receive(:zoho_resource_client).and_return(mock_zoho) | ||
end | ||
|
||
context "when accessed by a logged-in user" do | ||
let(:user) { create(:user) } | ||
|
||
before do | ||
fake_login_known_user(user) | ||
end | ||
|
||
context "when the user has no skin set" do | ||
before do | ||
admin_setting = AdminSetting.default | ||
admin_setting.default_skin = Skin.default | ||
admin_setting.save(validate: false) | ||
end | ||
|
||
it "sets the skin title in the Zoho ticket" do | ||
expect(mock_zoho).to receive(:create_ticket).with(ticket_attributes: include( | ||
"cf" => include( | ||
"cf_site_skin" => Skin.default.title | ||
) | ||
)) | ||
post :create, params: default_parameters | ||
end | ||
end | ||
|
||
context "when the user has a public non-default skin set" do | ||
let(:skin) { create(:skin, :public) } | ||
|
||
before do | ||
user.preference.update!(skin: skin) | ||
end | ||
|
||
it "sets the skin title in the Zoho ticket" do | ||
expect(mock_zoho).to receive(:create_ticket).with(ticket_attributes: include( | ||
"cf" => include( | ||
"cf_site_skin" => skin.title | ||
) | ||
)) | ||
post :create, params: default_parameters | ||
end | ||
end | ||
|
||
context "when the user has a private skin set" do | ||
let(:skin) { create(:skin, author: user) } | ||
|
||
before do | ||
user.preference.update!(skin: skin) | ||
end | ||
|
||
it "sets the expected fields in the support ticket" do | ||
expect(mock_zoho).to receive(:create_ticket).with(ticket_attributes: include( | ||
"cf" => include( | ||
"cf_site_skin" => "Custom skin" | ||
) | ||
)) | ||
post :create, params: default_parameters | ||
end | ||
end | ||
end | ||
|
||
context "when accessed by a guest" do | ||
context "when the referer is on the Archive" do | ||
before do | ||
request.env["HTTP_REFERER"] = "https://archiveofourown.org/works/1" | ||
end | ||
|
||
it "sets the referer in the Zoho ticket" do | ||
expect(mock_zoho).to receive(:create_ticket).with(ticket_attributes: include( | ||
"cf" => include( | ||
"cf_referer" => "https://archiveofourown.org/works/1", | ||
"cf_ip" => "0.0.0.0" | ||
) | ||
)) | ||
post :create, params: default_parameters | ||
end | ||
end | ||
|
||
context "when the referer is elsewhere" do | ||
before do | ||
request.env["HTTP_REFERER"] = "https://example.com/works/1" | ||
end | ||
|
||
it "does not set the referer in the Zoho ticket" do | ||
expect(mock_zoho).to receive(:create_ticket).with(ticket_attributes: include( | ||
"cf" => include( | ||
"cf_referer" => "Unknown URL", | ||
"cf_ip" => "0.0.0.0" | ||
) | ||
)) | ||
post :create, params: default_parameters | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe SkinsHelper do | ||
describe "#current_skin" do | ||
before do | ||
allow(helper).to receive(:current_user) | ||
allow(helper).to receive(:logged_in_as_admin?).and_return(false) | ||
allow(helper).to receive(:logged_in?).and_return(false) | ||
admin_setting = AdminSetting.default | ||
admin_setting.default_skin = Skin.default | ||
admin_setting.save(validate: false) | ||
end | ||
|
||
context "when the parameters include a skin id" do | ||
before do | ||
params[:site_skin] = skin.id | ||
end | ||
|
||
context "when the skin is applied" do | ||
let(:skin) { create(:skin, :public) } | ||
|
||
it "returns the skin matching the parameter" do | ||
expect(helper.current_skin).to eq(skin) | ||
end | ||
end | ||
|
||
context "when the skin is not applied" do | ||
let(:skin) { create(:skin) } | ||
|
||
it "falls back to other options" do | ||
expect(helper.current_skin).to eq(Skin.default) | ||
end | ||
end | ||
end | ||
|
||
context "when the current user has a skin set for the session" do | ||
before do | ||
allow(helper).to receive(:current_user).and_return(create(:user)) | ||
allow(helper).to receive(:logged_in?).and_return(true) | ||
session[:site_skin] = skin.id | ||
end | ||
|
||
context "when the skin is applied" do | ||
let(:skin) { create(:skin, :public) } | ||
|
||
it "returns the skin matching the session attribute" do | ||
expect(helper.current_skin).to eq(skin) | ||
end | ||
end | ||
|
||
context "when the skin is not applied" do | ||
# Non-public skin with a different author | ||
let(:skin) { create(:skin) } | ||
|
||
it "falls back to other options" do | ||
expect(helper.current_skin).to eq(Skin.default) | ||
end | ||
end | ||
end | ||
|
||
context "when the current user has a skin preference set" do | ||
let(:skin) { create(:skin) } | ||
let(:user) { skin.author } | ||
|
||
before do | ||
user.preference.update!(skin: skin) | ||
allow(helper).to receive(:current_user).and_return(user) | ||
end | ||
|
||
it "returns the preferred skin" do | ||
expect(helper.current_skin).to eq(skin) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.