-
Notifications
You must be signed in to change notification settings - Fork 2
/
github_bot_test.rb
61 lines (51 loc) · 1.46 KB
/
github_bot_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
# frozen_string_literal: true
require 'minitest/autorun'
require_relative 'github_bot'
require_relative 'github_bot_brain'
class GithubBotTest < Minitest::Test
KEY = OpenSSL::PKey::RSA.generate(1024)
attr_reader :bot
def setup
@tg = Minitest::Mock.new
@brain = GithubBotBrain.new
@bot = GithubBot.new(@brain, tg: @tg, private_key: KEY)
@bot.installation_client = Minitest::Mock.new
end
def repo(name, opts = {})
{
'id' => 1,
'name' => name
}.merge(opts)
end
def user(login)
{
'login' => login
}
end
def test_assign_reviewer
@brain.reviewers['ckb'] = %w[foo bar bot]
@bot.installation_client.expect :add_assignees, nil, [1, 9, ['foo']]
@bot.installation_client.expect :add_comment, nil, [1, 9, /@foo is assigned/]
@bot.assign_reviewer(
'repository' => repo('ckb'),
'pull_request' => {
'number' => 9,
'user' => user('bot')
}
)
assert_equal(@brain.reviewers['ckb'], %w[bar bot foo])
end
def test_assign_reviewer_when_next_is_self
@brain.reviewers['ckb'] = %w[foo bar bot]
@bot.installation_client.expect :add_assignees, nil, [1, 9, ['bar']]
@bot.installation_client.expect :add_comment, nil, [1, 9, /@bar is assigned/]
@bot.assign_reviewer(
'repository' => repo('ckb'),
'pull_request' => {
'number' => 9,
'user' => user('foo')
}
)
assert_equal(@brain.reviewers['ckb'], %w[foo bot bar])
end
end