fix: stabilize store review channel integration
This commit is contained in:
@@ -4,6 +4,7 @@ class GooglePlay::CallbacksController < ApplicationController
|
||||
def show
|
||||
return redirect_with_error(params[:error]) if params[:error].present?
|
||||
|
||||
account
|
||||
token = google_client.auth_code.get_token(params[:code], redirect_uri: google_play_callback_url)
|
||||
inbox = create_channel_with_inbox(token)
|
||||
|
||||
|
||||
@@ -8,16 +8,17 @@ RSpec.describe 'GooglePlay::CallbacksController', type: :request do
|
||||
let(:token_response) do
|
||||
{ access_token: 'play-access-token', refresh_token: 'play-refresh-token', token_type: 'Bearer', expires_in: 3599 }
|
||||
end
|
||||
let(:token_url) { 'https://accounts.google.com/o/oauth2/token' }
|
||||
|
||||
before do
|
||||
create(:installation_config, name: 'GOOGLE_OAUTH_CLIENT_ID', value: 'client-id-123', locked: false)
|
||||
create(:installation_config, name: 'GOOGLE_OAUTH_CLIENT_SECRET', value: 'client-secret', locked: false)
|
||||
configure_google_oauth('GOOGLE_OAUTH_CLIENT_ID', 'client-id-123')
|
||||
configure_google_oauth('GOOGLE_OAUTH_CLIENT_SECRET', 'client-secret')
|
||||
GlobalConfig.clear_cache
|
||||
end
|
||||
|
||||
describe 'GET /google_play/callback' do
|
||||
it 'creates the channel + inbox and redirects to the agent assignment page' do
|
||||
stub_request(:post, 'https://oauth2.googleapis.com/o/oauth2/token')
|
||||
stub_request(:post, token_url)
|
||||
.to_return(status: 200, body: token_response.to_json, headers: { 'Content-Type' => 'application/json' })
|
||||
|
||||
expect do
|
||||
@@ -41,7 +42,7 @@ RSpec.describe 'GooglePlay::CallbacksController', type: :request do
|
||||
end
|
||||
|
||||
it 'redirects to the inbox setup page with the error when token exchange fails' do
|
||||
stub_request(:post, 'https://oauth2.googleapis.com/o/oauth2/token').to_return(status: 400, body: 'invalid')
|
||||
stub_request(:post, token_url).to_return(status: 400, body: 'invalid')
|
||||
|
||||
get '/google_play/callback', params: { code: code, state: state }
|
||||
|
||||
@@ -55,4 +56,9 @@ RSpec.describe 'GooglePlay::CallbacksController', type: :request do
|
||||
expect(response).to redirect_to('/')
|
||||
end
|
||||
end
|
||||
|
||||
def configure_google_oauth(name, value)
|
||||
config = InstallationConfig.find_or_initialize_by(name: name)
|
||||
config.update!(value: value, locked: false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,6 @@ require 'rails_helper'
|
||||
RSpec.describe Inboxes::FetchGooglePlayReviewInboxesJob do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
before { clear_enqueued_jobs }
|
||||
|
||||
let!(:due_channel) { create(:channel_google_play, last_synced_at: 2.hours.ago) }
|
||||
let!(:fresh_channel) { create(:channel_google_play, last_synced_at: 5.minutes.ago) }
|
||||
let!(:never_synced_channel) { create(:channel_google_play, last_synced_at: nil) }
|
||||
|
||||
@@ -53,7 +53,7 @@ RSpec.describe Channel::GooglePlay do
|
||||
let(:base_url) { "#{described_class::API_BASE_URL}/applications/#{channel.app_id}/reviews" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).to receive(:access_token).and_return('test-token')
|
||||
allow(channel).to receive(:access_token).and_return('test-token')
|
||||
end
|
||||
|
||||
it 'returns the reviews list for a single page' do
|
||||
@@ -93,7 +93,7 @@ RSpec.describe Channel::GooglePlay do
|
||||
let(:url) { "#{described_class::API_BASE_URL}/applications/#{channel.app_id}/reviews/REV-1:reply" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).to receive(:access_token).and_return('test-token')
|
||||
allow(channel).to receive(:access_token).and_return('test-token')
|
||||
end
|
||||
|
||||
it 'returns a source_id composed from the review id and lastEdited.seconds' do
|
||||
|
||||
@@ -56,6 +56,7 @@ RSpec.describe Conversations::MessageWindowService do
|
||||
describe 'on Facebook channels' do
|
||||
before do
|
||||
stub_request(:post, /graph.facebook.com/)
|
||||
InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').delete_all
|
||||
GlobalConfig.clear_cache
|
||||
end
|
||||
|
||||
@@ -199,6 +200,11 @@ RSpec.describe Conversations::MessageWindowService do
|
||||
end
|
||||
|
||||
describe 'on Instagram channels' do
|
||||
before do
|
||||
InstallationConfig.where(name: 'ENABLE_INSTAGRAM_CHANNEL_HUMAN_AGENT').delete_all
|
||||
GlobalConfig.clear_cache
|
||||
end
|
||||
|
||||
let!(:instagram_channel) { create(:channel_instagram) }
|
||||
let!(:instagram_inbox) { create(:inbox, channel: instagram_channel, account: instagram_channel.account) }
|
||||
let!(:conversation) { create(:conversation, inbox: instagram_inbox, account: instagram_channel.account) }
|
||||
|
||||
@@ -11,7 +11,6 @@ RSpec.describe GooglePlay::SendOnGooglePlayService do
|
||||
describe '#perform' do
|
||||
it 'stamps the outgoing message with the source_id returned from the API' do
|
||||
allow(channel).to receive(:reply_to_review).with('REV-1', 'thanks').and_return('REV-1::reply::42')
|
||||
allow_any_instance_of(Inbox).to receive(:channel).and_return(channel)
|
||||
|
||||
described_class.new(message: message).perform
|
||||
|
||||
@@ -21,7 +20,6 @@ RSpec.describe GooglePlay::SendOnGooglePlayService do
|
||||
|
||||
it 'marks the message as failed when the API call raises' do
|
||||
allow(channel).to receive(:reply_to_review).and_raise(StandardError, 'Google Play reply failed (403)')
|
||||
allow_any_instance_of(Inbox).to receive(:channel).and_return(channel)
|
||||
allow(ChatwootExceptionTracker).to receive(:new).and_call_original
|
||||
|
||||
described_class.new(message: message).perform
|
||||
|
||||
Reference in New Issue
Block a user