This repository has been 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
/
basecamp_test.rb
90 lines (73 loc) · 2.6 KB
/
basecamp_test.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
require File.expand_path('../helper', __FILE__)
class BasecampTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
@options = {
'project_url' => 'https://basecamp.com/123/projects/456',
'email_address' => 'a@b.com',
'password' => 'secret' }
end
def test_push
@stubs.post '/123/api/v1/projects/456/events.json' do |env|
assert_equal 'https', env[:url].scheme
assert_equal 'basecamp.com', env[:url].host
assert_equal 'Basic YUBiLmNvbTpzZWNyZXQ=', env[:request_headers]['Authorization']
assert_match 'GitHub', env[:request_headers]['User-Agent']
assert_equal 'application/json', env[:request_headers]['Content-Type']
assert_equal 'application/json', env[:request_headers]['Accept']
expected = {
'service' => Service::Basecamp::SERVICE_NAME,
'logo_url' => Service::Basecamp::LOGO_URL,
'creator_email_address' => 'tom@mojombo.com',
'description' => 'committed',
'title' => 'pushed 3 new commits to master',
'url' => 'http://github.com/mojombo/grit/compare/4c8124f...a47fd41' }
assert_equal expected, JSON.parse(env[:body])
[200, {}, '']
end
service(@options, payload).receive_push
end
def test_pull
@stubs.post '/123/api/v1/projects/456/events.json' do |env|
expected = {
'service' => Service::Basecamp::SERVICE_NAME,
'logo_url' => Service::Basecamp::LOGO_URL,
'creator_email_address' => nil,
'description' => 'opened a pull request',
'title' => 'booya (master..feature)',
'url' => 'html_url' }
assert_equal expected, JSON.parse(env[:body])
[200, {}, '']
end
service(:pull_request, @options, pull_payload).receive_pull_request
end
def test_issues
@stubs.post '/123/api/v1/projects/456/events.json' do |env|
expected = {
'service' => Service::Basecamp::SERVICE_NAME,
'logo_url' => Service::Basecamp::LOGO_URL,
'creator_email_address' => nil,
'description' => 'opened an issue',
'title' => 'booya',
'url' => 'html_url' }
assert_equal expected, JSON.parse(env[:body])
[200, {}, '']
end
service(:issues, @options, issues_payload).receive_issues
end
def service(*args)
super Service::Basecamp, *args
end
# No html_url in default payload
def pull_payload
super.tap do |payload|
payload['pull_request']['html_url'] = 'html_url'
end
end
# No html_url in default payload
def issues_payload
super.tap do |payload|
payload['issue']['html_url'] = 'html_url'
end
end
end