This repository was archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsmartling_test.rb
More file actions
159 lines (140 loc) · 4 KB
/
Copy pathsmartling_test.rb
File metadata and controls
159 lines (140 loc) · 4 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
require File.expand_path('../helper', __FILE__)
class SmartlingTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
end
def test_requires_service_url
data = self.data.update("service_url" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_requires_project_id
data = self.data.update("project_id" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_requires_api_key
data = self.data.update("api_key" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_requires_config_path
data = self.data.update("config_path" => "")
svc = service :push, data, payload
assert_raises Service::ConfigurationError do
svc.receive
end
end
def test_requires_master_only_no_master
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def test_requires_master_only_no_branch
payload = self.payload.update("ref" => "refs/heads/branch_name")
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def test_requires_master_only_nil_master
data = self.data.update("master_only" => nil)
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def test_requires_master_only_nil_branch
data = self.data.update("master_only" => nil)
payload = self.payload.update("ref" => "refs/heads/branch_name")
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def test_requires_master_only_yes_master
data = self.data.update("master_only" => "1")
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def test_requires_master_only_yes_branch
payload = self.payload.update("ref" => "refs/heads/branch_name")
data = self.data.update("master_only" => "1")
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
begin
@stubs.verify_stubbed_calls
rescue RuntimeError
else
assert_true false
end
end
def test_error
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
[401, {}, '']
end
svc = service :push, data, payload
begin
svc.receive
rescue Service::ConfigurationError
else
assert_true false
end
@stubs.verify_stubbed_calls
end
def test_ok
@stubs.post "/github" do |env|
assert_equal "capi.smatling.com", env[:url].host
body = JSON.parse(env[:body])
assert_equal data["project_id"], body.delete("projectId")
assert_equal data["api_key"], body.delete("apiKey")
assert_equal data["config_path"], body.delete("resourceFile")
assert_equal payload, body
[200, {}, '']
end
svc = service :push, data, payload
svc.receive
@stubs.verify_stubbed_calls
end
def data
{
"service_url" => "http://capi.smatling.com",
"project_id" => "d86077368",
"api_key" => "2c1ad0bb-e9b6-4c20-b536-1006502644a2",
"config_path" => "smartling-config.json",
"master_only" => "0"
}
end
def service(*args)
super Service::Smartling, *args
end
end