Skip to content

Commit

Permalink
Merge pull request #313 from EasyPost/new_webhook_fixtures
Browse files Browse the repository at this point in the history
chore: use new webhook fixtures in tests
  • Loading branch information
Justintime50 committed Aug 14, 2024
2 parents 1c8a3d6 + 08cb171 commit dcc93ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
16 changes: 12 additions & 4 deletions spec/support/fixture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ def self.report_date
'2022-06-11'
end

def self.webhook_url
read_fixture_data['webhook_url']
end

def self.ca_address1
read_fixture_data['addresses']['ca_address_1']
end
Expand Down Expand Up @@ -132,6 +128,18 @@ def self.event_bytes
JSON.parse(data).to_json.encode('UTF-8')
end

def self.webhook_hmac_signature
read_fixture_data['webhook_hmac_signature']
end

def self.webhook_secret
read_fixture_data['webhook_secret']
end

def self.webhook_url
read_fixture_data['webhook_url']
end

# The credit card details below are for a valid proxy card usable
# for tests only and cannot be used for real transactions.
# DO NOT alter these details with real credit card information.
Expand Down
9 changes: 4 additions & 5 deletions spec/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@

describe '.validate_webhook' do
it 'validate a webhook' do
webhook_secret = 'sécret'
expected_hmac_signature = 'hmac-sha256-hex=e93977c8ccb20363d51a62b3fe1fc402b7829be1152da9e88cf9e8d07115a46b'
headers = {
'X-Hmac-Signature' => expected_hmac_signature,
'X-Hmac-Signature' => Fixture.webhook_hmac_signature,
}

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

it 'validate a webhook with invalid secret' do
Expand Down

0 comments on commit dcc93ff

Please sign in to comment.