Sha256: 6e21a40b581decc12dcaadedb82ef8fe46c93352ee381f7e8b031fc8e5c37c73
Contents?: true
Size: 1.67 KB
Versions: 3
Compression:
Stored size: 1.67 KB
Contents
require 'spec_helper' RSpec.feature "Can register a handler and receive Webhooks", type: :request do background do SolidusWebhooks.reset_config! SolidusWebhooks.config.register_webhook_handler :foo, foo_handler SolidusWebhooks.config.register_webhook_handler :bar, bar_handler end let(:foo_payloads) { [] } let(:bar_payloads) { [] } let(:foo_handler) { ->(payload) { foo_payloads << payload } } let(:bar_handler) { ->(payload) { bar_payloads << payload } } let(:token) { create(:admin_user, spree_api_key: "123").spree_api_key } let(:token_without_permission) { create(:user, spree_api_key: "456").spree_api_key } scenario "calls the handler passing the payload" do post "/webhooks/foo?token=#{token}", as: :json, params: {a: 123} expect(response).to have_http_status(:ok) post "/webhooks/foo?token=#{token}", as: :json, params: {b: 456} expect(response).to have_http_status(:ok) post "/webhooks/bar?token=#{token}", as: :json, params: {c: 789} expect(response).to have_http_status(:ok) expect(foo_payloads).to eq([{'a' => 123}, {'b' => 456}]) expect(bar_payloads).to eq([{'c' => 789}]) end scenario "receives a bad handler id" do post "/webhooks/baz?token=#{token}", as: :json, params: {a: 123} expect(response).to have_http_status(:not_found) end scenario "refuses a bad token" do post "/webhooks/baz?token=b4d-t0k3n", as: :json, params: {a: 123} expect(response).to have_http_status(:unauthorized) end scenario "refuses a token without permissions" do post "/webhooks/foo?token=#{token_without_permission}", as: :json, params: {a: 123} expect(response).to have_http_status(:unauthorized) end end
Version data entries
3 entries across 3 versions & 1 rubygems