Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
add wanelo store id to shopify webhooks
Browse files Browse the repository at this point in the history
- maintains backwards compatibility
- [refs #89652052]
  • Loading branch information
Max Gurewitz & Tori Scallan authored and Greg Poirier & Max Gurewitz committed Mar 18, 2015
1 parent 6b6b784 commit 44f2b22
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class Web < Sinatra::Base
status 200
end

post %r{shopify/(?<wanelo_store_id>\w*)/(?<topic>\w*)/(?<action>\w*)} do
webhook = Oj.load(request.body.read)
routing_key = ['shopify', params['topic'], params['action']].join('.')
webhook['wanelo_store_id'] = params['wanelo_store_id']
Publisher::Shopify.new(webhook).publish(routing_key)
status 200
end

post %r{shopify/(?<topic>\w*)/(?<action>\w*)} do
webhook = Oj.load(request.body.read)
routing_key = ['shopify', params['topic'], params['action']].join('.')
Expand All @@ -42,4 +50,3 @@ class Web < Sinatra::Base
end
end
end

8 changes: 8 additions & 0 deletions spec/functional/shopify/lapine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ def rack_env(hmac)
message = queue.messages.pop
expect(message[1]).to eq({routing_key: 'shopify.orders.fulfilled'})
end

context 'with store id in path' do
it 'includes the store id in the message' do
post '/shopify/1/orders/fulfilled', body, rack_env(body_hmac)
message = queue.messages.pop
expect(Oj.load(message[0])['wanelo_store_id'].to_i).to eq(1)
end
end
end
7 changes: 7 additions & 0 deletions spec/functional/shopify/routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ def rack_env(hmac)
}
end

context 'with store id in path' do
it 'includes store id in payload' do
post '/shopify/1/orders/fulfilled', body, rack_env(body_hmac)
expect(last_response.status).to eq(200)
end
end

context 'with HTTP_X_SHOPIFY_HMAC_SHA256 header' do
context 'when submitted hmac and calculated hmac are the same' do
it 'continues' do
Expand Down

0 comments on commit 44f2b22

Please sign in to comment.