diff --git a/app/controllers/api/v1/instagram_callbacks_controller.rb b/app/controllers/webhooks/instagram_controller.rb similarity index 92% rename from app/controllers/api/v1/instagram_callbacks_controller.rb rename to app/controllers/webhooks/instagram_controller.rb index 0c7e7a94c..bd6fee1f5 100644 --- a/app/controllers/api/v1/instagram_callbacks_controller.rb +++ b/app/controllers/webhooks/instagram_controller.rb @@ -1,4 +1,4 @@ -class Api::V1::InstagramCallbacksController < ApplicationController +class Webhooks::InstagramController < ApplicationController skip_before_action :authenticate_user!, raise: false skip_before_action :set_current_user diff --git a/config/routes.rb b/config/routes.rb index c825911d7..3d629d2fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -256,8 +256,8 @@ Rails.application.routes.draw do post 'webhooks/line/:line_channel_id', to: 'webhooks/line#process_payload' post 'webhooks/telegram/:bot_token', to: 'webhooks/telegram#process_payload' post 'webhooks/whatsapp/:phone_number', to: 'webhooks/whatsapp#process_payload' - get 'instagram_callbacks/event', to: 'api/v1/instagram_callbacks#verify' - post 'instagram_callbacks/event', to: 'api/v1/instagram_callbacks#events' + get 'webhooks/instagram', to: 'webhooks/instagram#verify' + post 'webhooks/instagram', to: 'webhooks/instagram#events' namespace :twitter do resource :callback, only: [:show] diff --git a/spec/controllers/webhooks/instagram_controller_spec.rb b/spec/controllers/webhooks/instagram_controller_spec.rb new file mode 100644 index 000000000..fce701587 --- /dev/null +++ b/spec/controllers/webhooks/instagram_controller_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe 'Webhooks::InstagramController', type: :request do + describe 'POST /webhooks/instagram' do + let!(:dm_params) { build(:instagram_message_create_event).with_indifferent_access } + + it 'call the instagram events job with the params' do + allow(::Webhooks::InstagramEventsJob).to receive(:perform_later) + expect(::Webhooks::InstagramEventsJob).to receive(:perform_later) + + instagram_params = dm_params.merge(object: 'instagram') + post '/webhooks/instagram', params: instagram_params + expect(response).to have_http_status(:success) + end + end +end