@@ -27,16 +27,64 @@ def test_pull_request_status_success
27
27
} )
28
28
end
29
29
30
- def test_pull_request_test_success
30
+ def test_pull_request_status_test_success
31
31
@stubs . post ( "/repos/pbrisbin/foo/statuses/#{ "0" * 40 } " ) { |env | [ 422 , { } , "" ] }
32
32
33
- assert receive_test ( { } , { github_slug : "pbrisbin/foo" } ) [ :ok ] , "Expected test of pull request to be true"
33
+ assert receive_test ( { update_status : true } , { github_slug : "pbrisbin/foo" } ) [ :ok ] , "Expected test of pull request to be true"
34
34
end
35
35
36
- def test_pull_request_test_failure
36
+ def test_pull_request_status_test_failure
37
37
@stubs . post ( "/repos/pbrisbin/foo/statuses/#{ "0" * 40 } " ) { |env | [ 401 , { } , "" ] }
38
38
39
- assert !receive_test ( { } , { github_slug : "pbrisbin/foo" } ) [ :ok ] , "Expected failed test of pull request"
39
+ assert !receive_test ( { update_status : true } , { github_slug : "pbrisbin/foo" } ) [ :ok ] , "Expected failed test of pull request"
40
+ end
41
+
42
+ def test_pull_request_comment_test_success
43
+ @stubs . get ( "/user" ) { |env | [ 200 , { "x-oauth-scopes" => "gist, user, repo" } , "" ] }
44
+
45
+ assert receive_test ( { add_comment : true } ) [ :ok ] , "Expected test of pull request to be true"
46
+ end
47
+
48
+ def test_pull_request_comment_test_failure_insufficient_permissions
49
+ @stubs . get ( "/user" ) { |env | [ 200 , { "x-oauth-scopes" => "gist, user" } , "" ] }
50
+
51
+ assert !receive_test ( { add_comment : true } ) [ :ok ] , "Expected failed test of pull request"
52
+ end
53
+
54
+ def test_pull_request_comment_test_failure_bad_token
55
+ @stubs . get ( "/user" ) { |env | [ 401 , { } , "" ] }
56
+
57
+ assert !receive_test ( { add_comment : true } ) [ :ok ] , "Expected failed test of pull request"
58
+ end
59
+
60
+ def test_pull_request_success_both
61
+ @stubs . post ( "/repos/pbrisbin/foo/statuses/#{ "0" * 40 } " ) { |env | [ 422 , { } , "" ] }
62
+ @stubs . get ( "/user" ) { |env | [ 200 , { "x-oauth-scopes" => "gist, user, repo" } , "" ] }
63
+
64
+ assert receive_test ( { update_status : true , add_comment : true } , { github_slug : "pbrisbin/foo" } ) [ :ok ] , "Expected test of pull request to be true"
65
+ end
66
+
67
+ def test_response_aggregator_success
68
+ response = aggregrate_response ( { ok : true , message : "OK" } , { ok : true , message : "OK 2" } )
69
+ assert_equal response , { ok : true , message : "OK" }
70
+ end
71
+
72
+ def test_response_aggregator_failure_both
73
+ response = aggregrate_response ( { ok : false , message : "Bad Token" } , { ok : false , message : "Bad Stuff" } )
74
+ assert_equal response , { ok : false , message : "Unable to post comment or update status" }
75
+ end
76
+
77
+ def test_response_aggregator_failure_status
78
+ response = aggregrate_response ( { ok : false , message : "Bad Token" } , { ok : true , message : "OK" } )
79
+ assert !response [ :ok ] , "Expected invalid response because status response is invalid"
80
+ assert_match /Bad Token/ , response [ :message ]
81
+ end
82
+
83
+
84
+ def test_response_aggregator_failure_status
85
+ response = aggregrate_response ( { ok : true , message : "OK" } , { ok : false , message : "Bad Stuff" } )
86
+ assert !response [ :ok ] , "Expected invalid response because comment response is invalid"
87
+ assert_match /Bad Stuff/ , response [ :message ]
40
88
end
41
89
42
90
def test_pull_request_comment
@@ -104,12 +152,16 @@ def receive_pull_request(config, event_data)
104
152
)
105
153
end
106
154
107
- def receive_test ( config , event_data )
155
+ def receive_test ( config , event_data = { } )
108
156
receive (
109
157
CC ::Service ::GitHubPullRequests ,
110
158
{ oauth_token : "123" } . merge ( config ) ,
111
159
{ name : "test" } . merge ( event_data )
112
160
)
113
161
end
114
162
163
+ def aggregrate_response ( status_response , comment_response )
164
+ CC ::Service ::GitHubPullRequests ::ResponseAggregator . new ( status_response , comment_response ) . response
165
+ end
166
+
115
167
end
0 commit comments