-
Notifications
You must be signed in to change notification settings - Fork 538
/
Copy pathabuse_reporter_spec.rb
101 lines (81 loc) · 3.04 KB
/
abuse_reporter_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# frozen_string_literal: true
require "spec_helper"
describe AbuseReporter do
include ZohoClientSpecHelper
let(:abuse_report_attributes) do
{
title: "This is a tragesy",
description: "Nothing more to say",
language: "English",
email: "[email protected]",
username: "Walrus",
ip_address: "127.0.0.1",
url: "http://localhost",
creator_ids: "3, 4"
}
end
let(:expected_ticket_attributes) do
{
"departmentId" => "abuse_dep_id",
"email" => "[email protected]",
"contactId" => "1",
"subject" => "[AO3] Abuse - This is a tragesy",
"description" => "Nothing more to say",
"cf" => {
"cf_language" => "English",
"cf_name" => "Walrus",
"cf_ip" => "127.0.0.1",
"cf_url" => "http://localhost",
"cf_user_id" => "3, 4"
}
}
end
before(:each) do
stub_const("ArchiveConfig", OpenStruct.new(ArchiveConfig))
ArchiveConfig.ABUSE_ZOHO_DEPARTMENT_ID = "abuse_dep_id"
stub_zoho_auth_client
stub_zoho_resource_client
end
let(:subject) { AbuseReporter.new(abuse_report_attributes) }
describe "#report_attributes" do
it "returns the expected attributes" do
expect(subject.report_attributes).to eq(expected_ticket_attributes)
end
context "if the report has an empty title" do
it "returns a hash containing a placeholder subject" do
allow(subject).to receive(:title).and_return("")
expect(subject.report_attributes.fetch("subject")).to eq("[AO3] Abuse - No Subject")
end
end
context "if the report does not have a description" do
it "returns a hash containing placeholder text" do
allow(subject).to receive(:description).and_return("")
expect(subject.report_attributes.fetch("description")).to eq("No comment submitted.")
end
end
context "if the report does not have an IP address" do
it "returns a hash containing 'Unknown IP'" do
allow(subject).to receive(:ip_address).and_return("")
expect(subject.report_attributes.fetch("cf").fetch("cf_ip")).to eq("Unknown IP")
end
end
context "if the report does not have an URL" do
it "returns a hash containing 'Unknown URL'" do
allow(subject).to receive(:url).and_return("")
expect(subject.report_attributes.fetch("cf").fetch("cf_url")).to eq("Unknown URL")
end
end
context "if the report has an image in description" do
it "strips all img tags but leaves the src URLs" do
allow(subject).to receive(:description).and_return('Hi!<img src="http://example.com/Camera-icon.svg">Bye!')
expect(subject.report_attributes.fetch("description")).to eq("Hi!http://example.com/Camera-icon.svgBye!")
end
end
context "if the report does not have creator_ids" do
it "returns a hash containing a blank string for the user id" do
allow(subject).to receive(:creator_ids).and_return(nil)
expect(subject.report_attributes.fetch("cf").fetch("cf_user_id")).to eq("")
end
end
end
end