-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgithub_webhooks_controller_push_spec.rb
73 lines (57 loc) · 2.18 KB
/
github_webhooks_controller_push_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
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe GithubWebhooksController do
let(:github_webhook_secret) { 'secret' }
let(:params) do
{
ref:,
commits:
}
end
let(:headers) do
{
'X-Hub-Signature-256': "sha256=#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), github_webhook_secret, params.to_json)}",
'X-GitHub-Event': 'push',
'Content-Type': 'application/json'
}
end
before do
allow(Rails.configuration.x.github_webhook).to receive(:secret).and_return(github_webhook_secret)
allow(Rails.configuration.x.github_webhook).to receive(:ref).and_return('branches/whatever')
allow(UploadJob).to receive(:perform_later)
post '/github_webhooks', env: { RAW_POST_DATA: params.to_json }, headers:
end
shared_examples 'upload job' do
it 'schedules the job' do
expect(UploadJob).to have_received(:perform_later).with(params)
end
end
describe 'when webhook ref matches branch of interest on github push' do
let(:ref) { 'branches/whatever' }
context 'when code has been added' do
let(:commits) { [{ added: ['en/code/project1/main.py'], modified: [], removed: [] }] }
it_behaves_like 'upload job'
end
context 'when code has been modified' do
let(:commits) { [{ added: [], modified: ['en/code/project1/main.py'], removed: [] }] }
it_behaves_like 'upload job'
end
context 'when code has been removed' do
let(:commits) { [{ added: [], modified: [], removed: ['en/code/project1/main.py'] }] }
it_behaves_like 'upload job'
end
context 'when code has not been changed' do
let(:commits) { [{ added: ['en/step2.md'], modified: ['en/step1.md'], removed: ['en/step0.md'] }] }
it 'does not schedule the upload job' do
expect(UploadJob).not_to have_received(:perform_later)
end
end
end
describe 'when webhook ref does not match branch of interest on github push' do
let(:ref) { 'branches/master' }
let(:commits) { [{ added: [], modified: ['en/code/project1/main.py'], removed: [] }] }
it 'does not schedule the upload job' do
expect(UploadJob).not_to have_received(:perform_later)
end
end
end