-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathwebhook_spec.rb
More file actions
68 lines (57 loc) · 1.58 KB
/
webhook_spec.rb
File metadata and controls
68 lines (57 loc) · 1.58 KB
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
require 'spec_helper'
RSpec.describe Webhook do
describe 'validating a webhook signature' do
let(:action) { Webhook.valid_signature? signature, url, params, files }
let(:signature) { '64a735ef0c47a0ae671e381c046648f0966deb29' }
let(:url) { 'example.com' }
let(:params) { {test: true} }
let(:files) { [] }
it 'raises an error if Phaxio::Config.webhook_token is unset' do
Phaxio.webhook_token = nil
expect {
action
}.to raise_error(Phaxio::Error::PhaxioError, 'No webhook token has been set')
end
context 'signature matches' do
it 'returns true' do
result = action
expect(result).to eq(true)
end
end
context 'signature does not match' do
let(:signature) { 'wrong' }
it 'returns false' do
result = action
expect(result).to eq(false)
end
end
context 'with files' do
let(:signature) { '1d2426c242a8c5de7eb1d9b662b7fda1d0b6edab' }
let(:params) { { test: true } }
let(:file1) do
tempfile = Tempfile.new
tempfile.write("foo")
tempfile
end
let(:file2) do
tempfile = Tempfile.new
tempfile.write("bar")
tempfile
end
let(:files) do
[
{ name: 'file', tempfile: file1 },
{ name: 'file', tempfile: file2 }
]
end
it 'returns true' do
result = action
expect(result).to eq(true)
end
it 'rewinds the files' do
action
expect(files.all? { |f| f[:tempfile].pos.zero? }).to eq(true)
end
end
end
end