Skip to content

Commit dcc93ff

Browse files
authored
Merge pull request #313 from EasyPost/new_webhook_fixtures
chore: use new webhook fixtures in tests
2 parents 1c8a3d6 + 08cb171 commit dcc93ff

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

spec/support/fixture.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ def self.report_date
4141
'2022-06-11'
4242
end
4343

44-
def self.webhook_url
45-
read_fixture_data['webhook_url']
46-
end
47-
4844
def self.ca_address1
4945
read_fixture_data['addresses']['ca_address_1']
5046
end
@@ -132,6 +128,18 @@ def self.event_bytes
132128
JSON.parse(data).to_json.encode('UTF-8')
133129
end
134130

131+
def self.webhook_hmac_signature
132+
read_fixture_data['webhook_hmac_signature']
133+
end
134+
135+
def self.webhook_secret
136+
read_fixture_data['webhook_secret']
137+
end
138+
139+
def self.webhook_url
140+
read_fixture_data['webhook_url']
141+
end
142+
135143
# The credit card details below are for a valid proxy card usable
136144
# for tests only and cannot be used for real transactions.
137145
# DO NOT alter these details with real credit card information.

spec/webhook_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@
7575

7676
describe '.validate_webhook' do
7777
it 'validate a webhook' do
78-
webhook_secret = 'sécret'
79-
expected_hmac_signature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b'
8078
headers = {
81-
'X-Hmac-Signature' => expected_hmac_signature,
79+
'X-Hmac-Signature' => Fixture.webhook_hmac_signature,
8280
}
8381

84-
webhook_body = EasyPost::Util.validate_webhook(Fixture.event_bytes, headers, webhook_secret)
85-
expect(webhook_body['description']).to eq('batch.created')
82+
webhook_body = EasyPost::Util.validate_webhook(Fixture.event_bytes, headers, Fixture.webhook_secret)
83+
expect(webhook_body['description']).to eq('tracker.updated')
84+
expect(webhook_body['result']['weight']).to eq(136.0) # Ensure we convert floats properly
8685
end
8786

8887
it 'validate a webhook with invalid secret' do

0 commit comments

Comments
 (0)