-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathmessage_builder_spec.rb
158 lines (137 loc) · 6.03 KB
/
message_builder_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
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
require 'spec_helper'
require './lib/message_builder'
describe MessageBuilder do
subject(:message_builder) { MessageBuilder.new(pull_requests) }
let(:no_pull_requests) { {} }
let(:recent_pull_requests) do
{
'Remove all Import-related code' => {
'title' => 'Remove all Import-related code',
'link' => 'https://github.com/alphagov/whitehall/pull/2248',
'author' => 'tekin',
'repo' => 'whitehall',
'comments_count' => '5',
'thumbs_up' => '0',
'approved' => true,
'updated' => Date.parse('2015-07-17 ((2457221j, 0s, 0n), +0s, 2299161j)'),
'labels' => []
}
}
end
let(:old_and_new_pull_requests) do
{
'[FOR DISCUSSION ONLY] Remove Whitehall.case_study_preview_host' => {
'title' => '[FOR DISCUSSION ONLY] Remove Whitehall.case_study_preview_host',
'link' => 'https://github.com/alphagov/whitehall/pull/2266',
'author' => 'mattbostock',
'repo' => 'whitehall',
'comments_count' => '1',
'thumbs_up' => '1',
'approved' => false,
'updated' => Date.parse('2015-07-13 ((2457217j, 0s, 0n), +0s, 2299161j)'),
'labels' => []
},
'Remove all Import-related code' => {
'title' => 'Remove all Import-related code',
'link' => 'https://github.com/alphagov/whitehall/pull/2248',
'author' => 'tekin',
'repo' => 'whitehall',
'comments_count' => '5',
'thumbs_up' => '0',
'approved' => false,
'updated' => Date.parse('2015-07-17 ((2457221j, 0s, 0n), +0s, 2299161j)'),
'labels' => []
}
}
end
before { Timecop.freeze(Time.local(2015, 07, 18)) }
context 'with labels' do
let(:mood) { 'informative' }
let(:pull_requests) do
{
'My WIP' => {
'title' => 'My WIP',
'link' => 'https://github.com/org/repo/pull/42',
'author' => 'Agatha Christie',
'repo' => 'repo',
'comments_count' => '0',
'thumbs_up' => '0',
'approved' => false,
'updated' => Date.today,
'labels' => [
{ 'name' => 'wip' },
{ 'name' => 'blocked' }
]
}
}
end
it 'includes the labels in the built message' do
expect(message_builder.build).to include(
'[wip] [blocked] <https://github.com/org/repo/pull/42|My WIP> - 0 comments'
)
end
end
context 'pull requests are recent' do
let(:pull_requests) { recent_pull_requests }
it 'builds informative message' do
expect(message_builder.build).to eq("Hello team! \n\n Here are the pull requests that need to be reviewed today:\n\n1) *whitehall* | tekin | updated yesterday | :white_check_mark: \n<https://github.com/alphagov/whitehall/pull/2248|Remove all Import-related code> - 5 comments\n\nMerry reviewing!")
end
it 'has an informative poster mood' do
message_builder.build
expect(message_builder.poster_mood).to eq("informative")
end
end
context 'no pull requests' do
let(:pull_requests) { no_pull_requests }
it 'builds seal of approval message' do
expect(message_builder.build).to eq("Aloha team! It's a beautiful day! :happyseal: :happyseal: :happyseal:\n\nNo pull requests to review today! :rainbow: :sunny: :metal: :tada:")
end
it 'has an approval poster mood' do
message_builder.build
expect(pull_requests).to eq({})
expect(message_builder.poster_mood).to eq("approval")
end
end
context 'there are some PRs that are over 2 days old' do
let(:mood) { 'angry' }
let(:pull_requests) { old_and_new_pull_requests }
context "and some recent ones" do
before { Timecop.freeze(Time.local(2015, 07, 18)) }
it 'builds message' do
expect(message_builder.build).to eq("AAAAAAARGH! This pull request has not been updated in over 2 days.\n\n1) *whitehall* | mattbostock | updated 5 days ago | 1 :+1:\n<https://github.com/alphagov/whitehall/pull/2266|[FOR DISCUSSION ONLY] Remove Whitehall.case_study_preview_host> - 1 comment\n\nRemember each time you forget to review your pull requests, a baby seal dies.\n \n\nThere are also these pull requests that need to be reviewed today:\n\n1) *whitehall* | tekin | updated yesterday\n<https://github.com/alphagov/whitehall/pull/2248|Remove all Import-related code> - 5 comments\n ")
end
end
context "but no recent ones" do
before { Timecop.freeze(Time.local(2015, 07, 16)) }
it 'builds message' do
expect(message_builder.build).to eq("AAAAAAARGH! This pull request has not been updated in over 2 days.\n\n1) *whitehall* | mattbostock | updated 3 days ago | 1 :+1:\n<https://github.com/alphagov/whitehall/pull/2266|[FOR DISCUSSION ONLY] Remove Whitehall.case_study_preview_host> - 1 comment\n\nRemember each time you forget to review your pull requests, a baby seal dies.\n \n\nThere are also these pull requests that need to be reviewed today:\n\n1) *whitehall* | tekin | updated -1 days ago\n<https://github.com/alphagov/whitehall/pull/2248|Remove all Import-related code> - 5 comments\n ")
end
end
it 'has an angry poster mood' do
message_builder.build
expect(message_builder.poster_mood).to eq("angry")
end
end
context 'rotting' do
let(:pull_request) do
{ 'title' => '[FOR DISCUSSION ONLY] Remove Whitehall.case_study_preview_host', 'link' => 'https://github.com/alphagov/whitehall/pull/2266', 'author' => 'mattbostock', 'repo' => 'whitehall', 'comments_count' => '1', 'thumbs_up' => '0', 'updated' => Date.parse('2015-07-13 ((2457217j,0s,0n),+0s,2299161j)') }
end
let(:pull_requests) { [pull_request] }
context 'old PR' do
before do
Timecop.freeze(Time.local(2015, 07, 16))
end
it 'is rotten' do
expect(message_builder).to be_rotten(pull_request)
end
end
context 'recent PR' do
before do
Timecop.freeze(Time.local(2015, 07, 15))
end
it 'is not rotten' do
expect(message_builder).to_not be_rotten(pull_request)
end
end
end
end