From 44f2b220f8d4c3517abdf1f2662132dc2e0ec608 Mon Sep 17 00:00:00 2001 From: Max Gurewitz & Tori Scallan Date: Tue, 17 Mar 2015 15:29:35 -0700 Subject: [PATCH] add wanelo store id to shopify webhooks - maintains backwards compatibility - [refs #89652052] --- lib/webhook.rb | 9 ++++++++- spec/functional/shopify/lapine_spec.rb | 8 ++++++++ spec/functional/shopify/routing_spec.rb | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/webhook.rb b/lib/webhook.rb index 51c505c..a2bc0e7 100644 --- a/lib/webhook.rb +++ b/lib/webhook.rb @@ -33,6 +33,14 @@ class Web < Sinatra::Base status 200 end + post %r{shopify/(?\w*)/(?\w*)/(?\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/(?\w*)/(?\w*)} do webhook = Oj.load(request.body.read) routing_key = ['shopify', params['topic'], params['action']].join('.') @@ -42,4 +50,3 @@ class Web < Sinatra::Base end end end - diff --git a/spec/functional/shopify/lapine_spec.rb b/spec/functional/shopify/lapine_spec.rb index 5128155..66cbb36 100644 --- a/spec/functional/shopify/lapine_spec.rb +++ b/spec/functional/shopify/lapine_spec.rb @@ -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 diff --git a/spec/functional/shopify/routing_spec.rb b/spec/functional/shopify/routing_spec.rb index edec6e7..83c8df0 100644 --- a/spec/functional/shopify/routing_spec.rb +++ b/spec/functional/shopify/routing_spec.rb @@ -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