mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-28 17:52:39 +00:00
chore: Enable the new Rubocop rules (#7122)
fixes: https://linear.app/chatwoot/issue/CW-1574/renable-the-disabled-rubocop-rules
This commit is contained in:
54
.rubocop.yml
54
.rubocop.yml
@@ -162,41 +162,33 @@ Rails/RenderInline:
|
||||
Performance/CollectionLiteralInLoop:
|
||||
Exclude:
|
||||
- 'db/migrate/20210315101919_enable_email_channel.rb'
|
||||
RSpec/NamedSubject:
|
||||
Enabled: false
|
||||
Style/RedundantConstantBase:
|
||||
Enabled: false
|
||||
Rails/RootPathnameMethods:
|
||||
Enabled: false
|
||||
RSpec/Rails/MinitestAssertions:
|
||||
Enabled: false
|
||||
RSpec/Rails/InferredSpecType:
|
||||
Enabled: false
|
||||
Rails/ThreeStateBooleanColumn:
|
||||
Exclude:
|
||||
- 'db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb'
|
||||
- 'db/migrate/20200605130625_agent_away_message_to_auto_reply.rb'
|
||||
- 'db/migrate/20200606132552_create_labels.rb'
|
||||
- 'db/migrate/20201027135006_create_working_hours.rb'
|
||||
- 'db/migrate/20210112174124_add_hmac_token_to_inbox.rb'
|
||||
- 'db/migrate/20210114202310_create_teams.rb'
|
||||
- 'db/migrate/20210212154240_add_request_for_email_on_channel_web_widget.rb'
|
||||
- 'db/migrate/20210428135041_add_campaigns.rb'
|
||||
- 'db/migrate/20210602182058_add_hmac_to_api_channel.rb'
|
||||
- 'db/migrate/20210609133433_add_email_collect_to_inboxes.rb'
|
||||
- 'db/migrate/20210618095823_add_csat_toggle_for_inbox.rb'
|
||||
- 'db/migrate/20210927062350_add_trigger_only_during_business_hours_collect_to_campaigns.rb'
|
||||
- 'db/migrate/20211027073553_add_imap_smtp_config_to_channel_email.rb'
|
||||
- 'db/migrate/20211109143122_add_tweet_enabled_flag_to_twitter_channel.rb'
|
||||
- 'db/migrate/20211216110209_add_allow_messages_after_resolved_to_inbox.rb'
|
||||
- 'db/migrate/20220116103902_add_open_ssl_verify_mode_to_channel_email.rb'
|
||||
- 'db/migrate/20220216151613_add_open_all_day_to_working_hour.rb'
|
||||
- 'db/migrate/20220511072655_add_archive_column_to_portal.rb'
|
||||
- 'db/migrate/20230503101201_create_sla_policies.rb'
|
||||
RSpec/IndexedLet:
|
||||
Enabled: false
|
||||
RSpec/MatchArray:
|
||||
Enabled: false
|
||||
Rails/ResponseParsedBody:
|
||||
Enabled: false
|
||||
RSpec/FactoryBot/ConsistentParenthesesStyle:
|
||||
Enabled: false
|
||||
Rails/ThreeStateBooleanColumn:
|
||||
Enabled: false
|
||||
Rails/Pluck:
|
||||
Enabled: false
|
||||
Rails/TopLevelHashWithIndifferentAccess:
|
||||
Enabled: false
|
||||
Rails/ActionOrder:
|
||||
Enabled: false
|
||||
Style/ArrayIntersect:
|
||||
Enabled: false
|
||||
RSpec/NoExpectationExample:
|
||||
Enabled: false
|
||||
Style/RedundantReturn:
|
||||
Enabled: false
|
||||
Rails/I18nLocaleTexts:
|
||||
RSpec/NamedSubject:
|
||||
Enabled: false
|
||||
|
||||
|
||||
# we should bring this down
|
||||
RSpec/MultipleMemoizedHelpers:
|
||||
Max: 14
|
||||
|
||||
@@ -16,6 +16,9 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
@article = @portal.articles.create!(article_params)
|
||||
@article.associate_root_article(article_params[:associated_article_id])
|
||||
@@ -23,10 +26,6 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController
|
||||
render json: { error: @article.errors.messages }, status: :unprocessable_entity and return unless @article.valid?
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@article.update!(article_params) if params[:article].present?
|
||||
render json: { error: @article.errors.messages }, status: :unprocessable_entity and return unless @article.valid?
|
||||
|
||||
@@ -6,6 +6,8 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont
|
||||
@automation_rules = Current.account.automation_rules
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@automation_rule = Current.account.automation_rules.new(automation_rules_permit)
|
||||
@automation_rule.actions = params[:actions]
|
||||
@@ -28,8 +30,6 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont
|
||||
render json: { blob_key: file_blob.key, blob_id: file_blob.id }
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
automation_rule_update
|
||||
|
||||
@@ -6,21 +6,21 @@ class Api::V1::Accounts::CampaignsController < Api::V1::Accounts::BaseController
|
||||
@campaigns = Current.account.campaigns
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@campaign = Current.account.campaigns.create!(campaign_params)
|
||||
end
|
||||
|
||||
def update
|
||||
@campaign.update!(campaign_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@campaign.destroy!
|
||||
head :ok
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@campaign.update!(campaign_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def campaign
|
||||
|
||||
@@ -9,6 +9,8 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle
|
||||
@categories = @portal.categories.search(params)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@category = @portal.categories.create!(category_params)
|
||||
@category.related_categories << related_categories_records
|
||||
@@ -17,8 +19,6 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle
|
||||
@category.save!
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@category.update!(category_params)
|
||||
@category.related_categories = related_categories_records if related_categories_records.any?
|
||||
|
||||
@@ -5,21 +5,21 @@ class Api::V1::Accounts::Contacts::NotesController < Api::V1::Accounts::Contacts
|
||||
@notes = @contact.notes.latest.includes(:user)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@note = @contact.notes.create!(note_params)
|
||||
end
|
||||
|
||||
def update
|
||||
@note.update(note_params)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@note.destroy!
|
||||
head :ok
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@note.update(note_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def note
|
||||
|
||||
@@ -26,6 +26,8 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||
@attachments = @conversation.attachments
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
@conversation = ConversationBuilder.new(params: params, contact_inbox: @contact_inbox).perform
|
||||
@@ -33,8 +35,6 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def filter
|
||||
result = ::Conversations::FilterService.new(params.permit!, current_user).perform
|
||||
@conversations = result[:conversations]
|
||||
|
||||
@@ -2,6 +2,11 @@ class Api::V1::Accounts::InboxMembersController < Api::V1::Accounts::BaseControl
|
||||
before_action :fetch_inbox
|
||||
before_action :current_agents_ids, only: [:create, :update]
|
||||
|
||||
def show
|
||||
authorize @inbox, :show?
|
||||
fetch_updated_agents
|
||||
end
|
||||
|
||||
def create
|
||||
authorize @inbox, :create?
|
||||
ActiveRecord::Base.transaction do
|
||||
@@ -10,11 +15,6 @@ class Api::V1::Accounts::InboxMembersController < Api::V1::Accounts::BaseControl
|
||||
fetch_updated_agents
|
||||
end
|
||||
|
||||
def show
|
||||
authorize @inbox, :show?
|
||||
fetch_updated_agents
|
||||
end
|
||||
|
||||
def update
|
||||
authorize @inbox, :update?
|
||||
update_agents_list
|
||||
|
||||
@@ -6,6 +6,10 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController
|
||||
@macros = Macro.with_visibility(current_user, params)
|
||||
end
|
||||
|
||||
def show
|
||||
head :not_found if @macro.nil?
|
||||
end
|
||||
|
||||
def create
|
||||
@macro = Current.account.macros.new(macros_with_user.merge(created_by_id: current_user.id))
|
||||
@macro.set_visibility(current_user, permitted_params)
|
||||
@@ -18,8 +22,16 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController
|
||||
@macro
|
||||
end
|
||||
|
||||
def show
|
||||
head :not_found if @macro.nil?
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
@macro.update!(macros_with_user)
|
||||
@macro.set_visibility(current_user, permitted_params)
|
||||
process_attachments
|
||||
@macro.save!
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e
|
||||
render json: { error: @macro.errors.messages }.to_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@@ -37,18 +49,6 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController
|
||||
render json: { blob_key: file_blob.key, blob_id: file_blob.id }
|
||||
end
|
||||
|
||||
def update
|
||||
ActiveRecord::Base.transaction do
|
||||
@macro.update!(macros_with_user)
|
||||
@macro.set_visibility(current_user, permitted_params)
|
||||
process_attachments
|
||||
@macro.save!
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e
|
||||
render json: { error: @macro.errors.messages }.to_json, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def execute
|
||||
::MacrosExecutionJob.perform_later(@macro, conversation_ids: params[:conversation_ids], user: Current.user)
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ class Api::V1::AccountsController < Api::BaseController
|
||||
CustomExceptions::Account::UserErrors,
|
||||
with: :render_error_response
|
||||
|
||||
def show
|
||||
@latest_chatwoot_version = ::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION)
|
||||
render 'api/v1/accounts/show', format: :json
|
||||
end
|
||||
|
||||
def create
|
||||
@user, @account = AccountBuilder.new(
|
||||
account_name: account_params[:account_name],
|
||||
@@ -35,11 +40,6 @@ class Api::V1::AccountsController < Api::BaseController
|
||||
render json: { cache_keys: get_cache_keys }, status: :ok
|
||||
end
|
||||
|
||||
def show
|
||||
@latest_chatwoot_version = ::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION)
|
||||
render 'api/v1/accounts/show', format: :json
|
||||
end
|
||||
|
||||
def update
|
||||
@account.update!(account_params.slice(:name, :locale, :domain, :support_email, :auto_resolve_duration))
|
||||
end
|
||||
|
||||
@@ -4,6 +4,16 @@ class DeviseOverrides::PasswordsController < Devise::PasswordsController
|
||||
skip_before_action :require_no_authentication, raise: false
|
||||
skip_before_action :authenticate_user!, raise: false
|
||||
|
||||
def create
|
||||
@user = User.find_by(email: params[:email])
|
||||
if @user
|
||||
@user.send_reset_password_instructions
|
||||
build_response(I18n.t('messages.reset_password_success'), 200)
|
||||
else
|
||||
build_response(I18n.t('messages.reset_password_failure'), 404)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
# params: reset_password_token, password, password_confirmation
|
||||
original_token = params[:reset_password_token]
|
||||
@@ -17,16 +27,6 @@ class DeviseOverrides::PasswordsController < Devise::PasswordsController
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.find_by(email: params[:email])
|
||||
if @user
|
||||
@user.send_reset_password_instructions
|
||||
build_response(I18n.t('messages.reset_password_success'), 200)
|
||||
else
|
||||
build_response(I18n.t('messages.reset_password_failure'), 404)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reset_password_and_confirmation(recoverable)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class DeviseOverrides::SessionsController < ::DeviseTokenAuth::SessionsController
|
||||
class DeviseOverrides::SessionsController < DeviseTokenAuth::SessionsController
|
||||
# Prevent session parameter from being passed
|
||||
# Unpermitted parameter: session
|
||||
wrap_parameters format: []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class DeviseOverrides::TokenValidationsController < ::DeviseTokenAuth::TokenValidationsController
|
||||
class DeviseOverrides::TokenValidationsController < DeviseTokenAuth::TokenValidationsController
|
||||
def validate_token
|
||||
# @resource will have been set by set_user_by_token concern
|
||||
if @resource
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class Platform::Api::V1::AccountsController < PlatformController
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@resource = Account.create!(account_params)
|
||||
update_resource_features
|
||||
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@resource.assign_attributes(account_params)
|
||||
update_resource_features
|
||||
|
||||
@@ -6,14 +6,14 @@ class Platform::Api::V1::AgentBotsController < PlatformController
|
||||
@resources = @platform_app.platform_app_permissibles.where(permissible_type: 'AgentBot').all
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@resource = AgentBot.new(agent_bot_params)
|
||||
@resource.save!
|
||||
@platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource)
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@resource.update!(agent_bot_params)
|
||||
end
|
||||
|
||||
@@ -5,6 +5,8 @@ class Platform::Api::V1::UsersController < PlatformController
|
||||
before_action(only: [:login]) { set_resource }
|
||||
before_action(only: [:login]) { validate_platform_app_permissible }
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
@resource = (User.find_by(email: user_params[:email]) || User.new(user_params))
|
||||
@resource.skip_confirmation!
|
||||
@@ -16,8 +18,6 @@ class Platform::Api::V1::UsersController < PlatformController
|
||||
render json: { url: @resource.generate_sso_link }
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
@resource.assign_attributes(user_update_params)
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon
|
||||
before_action :contact_inbox, except: [:create]
|
||||
before_action :process_hmac
|
||||
|
||||
def show; end
|
||||
|
||||
def create
|
||||
source_id = params[:source_id] || SecureRandom.uuid
|
||||
@contact_inbox = ::ContactInboxWithContactBuilder.new(
|
||||
@@ -11,8 +13,6 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon
|
||||
).perform
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
contact_identify_action = ContactIdentifyAction.new(
|
||||
contact: @contact_inbox.contact,
|
||||
|
||||
@@ -45,13 +45,17 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController
|
||||
|
||||
def seed
|
||||
Internal::SeedAccountJob.perform_later(requested_resource)
|
||||
# rubocop:disable Rails/I18nLocaleTexts
|
||||
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered')
|
||||
# rubocop:enable Rails/I18nLocaleTexts
|
||||
end
|
||||
|
||||
def destroy
|
||||
account = Account.find(params[:id])
|
||||
|
||||
DeleteObjectJob.perform_later(account) if account.present?
|
||||
# rubocop:disable Rails/I18nLocaleTexts
|
||||
redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account deletion is in progress.')
|
||||
# rubocop:enable Rails/I18nLocaleTexts
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class SwaggerController < ApplicationController
|
||||
def respond
|
||||
if Rails.env.development? || Rails.env.test?
|
||||
render inline: File.read(Rails.root.join('swagger', derived_path))
|
||||
render inline: Rails.root.join('swagger', derived_path).read
|
||||
else
|
||||
head :not_found
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ module Featurable
|
||||
check_for_column: false
|
||||
}.freeze
|
||||
|
||||
FEATURE_LIST = YAML.safe_load(File.read(Rails.root.join('config/features.yml'))).freeze
|
||||
FEATURE_LIST = YAML.safe_load(Rails.root.join('config/features.yml').read).freeze
|
||||
|
||||
FEATURES = FEATURE_LIST.each_with_object({}) do |feature, result|
|
||||
result[result.keys.size + 1] = "feature_#{feature['name']}".to_sym
|
||||
@@ -46,7 +46,7 @@ module Featurable
|
||||
end
|
||||
|
||||
def all_features
|
||||
FEATURE_LIST.map { |f| f['name'] }.index_with do |feature_name|
|
||||
FEATURE_LIST.pluck('name').index_with do |feature_name|
|
||||
feature_enabled?(feature_name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -233,8 +233,8 @@ class Conversation < ApplicationRecord
|
||||
|
||||
def allowed_keys?
|
||||
(
|
||||
(previous_changes.keys & %w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at priority]).present? ||
|
||||
(previous_changes['additional_attributes'].present? && (previous_changes['additional_attributes'][1].keys & %w[conversation_language]).present?)
|
||||
previous_changes.keys.intersect?(%w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at priority]) ||
|
||||
(previous_changes['additional_attributes'].present? && previous_changes['additional_attributes'][1].keys.intersect?(%w[conversation_language]))
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class InstallationConfig < ApplicationRecord
|
||||
# https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
|
||||
# FIX ME : fixes breakage of installation config. we need to migrate.
|
||||
# Fix configuration in application.rb
|
||||
serialize :serialized_value, HashWithIndifferentAccess
|
||||
serialize :serialized_value, ActiveSupport::HashWithIndifferentAccess
|
||||
|
||||
before_validation :set_lock
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -11,5 +11,5 @@ ActionCable::SubscriptionAdapter::Redis.redis_connector = lambda do |config|
|
||||
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75173
|
||||
# https://github.com/rails/rails/blob/4a23cb3415eac03d76623112576559a722d1f23d/actioncable/lib/action_cable/subscription_adapter/base.rb#L30
|
||||
config[:id] = nil if ENV['REDIS_DISABLE_CLIENT_COMMAND'].present?
|
||||
::Redis.new(config.except(:adapter, :channel_prefix))
|
||||
Redis.new(config.except(:adapter, :channel_prefix))
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class InstallAudited < ActiveRecord::Migration[6.1]
|
||||
# rubocop:disable RMetrics/MethodLength
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def self.up
|
||||
create_table :audits, :force => true do |t|
|
||||
t.bigint :auditable_id
|
||||
@@ -19,7 +19,7 @@ class InstallAudited < ActiveRecord::Migration[6.1]
|
||||
t.string :request_uuid
|
||||
t.datetime :created_at
|
||||
end
|
||||
# rubocop:enable RMetrics/MethodLength
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
add_index :audits, [:auditable_type, :auditable_id, :version], :name => 'auditable_index'
|
||||
add_index :audits, [:associated_type, :associated_id], :name => 'associated_index'
|
||||
|
||||
@@ -5,7 +5,7 @@ ConfigLoader.new.process
|
||||
## Seeds productions
|
||||
if Rails.env.production?
|
||||
# Setup Onboarding flow
|
||||
::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
end
|
||||
|
||||
## Seeds for Local Development
|
||||
@@ -46,7 +46,7 @@ unless Rails.env.production?
|
||||
inbox = Inbox.create!(channel: web_widget, account: account, name: 'Acme Support')
|
||||
InboxMember.create!(user: user, inbox: inbox)
|
||||
|
||||
contact_inbox = ::ContactInboxWithContactBuilder.new(
|
||||
contact_inbox = ContactInboxWithContactBuilder.new(
|
||||
source_id: user.id,
|
||||
inbox: inbox,
|
||||
hmac_verified: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CustomExceptions::Base < ::StandardError
|
||||
class CustomExceptions::Base < StandardError
|
||||
def to_hash
|
||||
{
|
||||
message: message
|
||||
|
||||
@@ -12,7 +12,7 @@ class Seeders::AccountSeeder
|
||||
def initialize(account:)
|
||||
raise 'Account Seeding is not allowed.' unless ENV.fetch('ENABLE_ACCOUNT_SEEDING', !Rails.env.production?)
|
||||
|
||||
@account_data = HashWithIndifferentAccess.new(YAML.safe_load(File.read(Rails.root.join('lib/seeders/seed_data.yml'))))
|
||||
@account_data = ActiveSupport::HashWithIndifferentAccess.new(YAML.safe_load(Rails.root.join('lib/seeders/seed_data.yml').read))
|
||||
@account = account
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::ContactIdentifyAction do
|
||||
describe ContactIdentifyAction do
|
||||
subject(:contact_identify) { described_class.new(contact: contact, params: params).perform }
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::ContactMergeAction do
|
||||
describe ContactMergeAction do
|
||||
subject(:contact_merge) { described_class.new(account: account, base_contact: base_contact, mergee_contact: mergee_contact).perform }
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Campaigns::CampaignConversationBuilder do
|
||||
describe Campaigns::CampaignConversationBuilder do
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:contact) { create(:contact, account: account, identifier: '123') }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::ContactInboxBuilder do
|
||||
describe ContactInboxBuilder do
|
||||
let(:account) { create(:account) }
|
||||
let(:contact) { create(:contact, email: 'xyc@example.com', phone_number: '+23423424123', account: account) }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::ContactInboxWithContactBuilder do
|
||||
describe ContactInboxWithContactBuilder do
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:contact) { create(:contact, email: 'xyc@example.com', phone_number: '+23423424123', account: account, identifier: '123') }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::ConversationBuilder do
|
||||
describe ConversationBuilder do
|
||||
let(:account) { create(:account) }
|
||||
let!(:sms_channel) { create(:channel_sms, account: account) }
|
||||
let!(:sms_inbox) { create(:inbox, channel: sms_channel, account: account) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::CsatSurveys::ResponseBuilder do
|
||||
describe CsatSurveys::ResponseBuilder do
|
||||
let(:message) do
|
||||
create(
|
||||
:message, content_type: :input_csat,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::Facebook::MessageBuilder do
|
||||
describe Messages::Facebook::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(incoming_fb_text_message, facebook_channel.inbox).perform }
|
||||
|
||||
before do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::Instagram::MessageBuilder do
|
||||
describe Messages::Instagram::MessageBuilder do
|
||||
subject(:instagram_message_builder) { described_class }
|
||||
|
||||
before do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::Messages::MessageBuilder do
|
||||
describe Messages::MessageBuilder do
|
||||
subject(:message_builder) { described_class.new(user, conversation, params).perform }
|
||||
|
||||
let(:account) { create(:account) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::NotificationBuilder do
|
||||
describe NotificationBuilder do
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
describe '#perform' do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe ::V2::ReportBuilder do
|
||||
describe V2::ReportBuilder do
|
||||
include ActiveJob::TestHelper
|
||||
let_it_be(:account) { create(:account) }
|
||||
let_it_be(:label_1) { create(:label, title: 'Label_1', account: account) }
|
||||
@@ -60,7 +60,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 10
|
||||
@@ -75,7 +75,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 20
|
||||
@@ -90,7 +90,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 50
|
||||
@@ -107,7 +107,7 @@ describe ::V2::ReportBuilder do
|
||||
|
||||
conversations = account.conversations.where('created_at < ?', 1.day.ago)
|
||||
conversations.each(&:resolved!)
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 0
|
||||
@@ -122,7 +122,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today].to_f).to be 0.48e4
|
||||
@@ -135,7 +135,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.summary
|
||||
|
||||
expect(metrics[:conversations_count]).to be 15
|
||||
@@ -153,7 +153,7 @@ describe ::V2::ReportBuilder do
|
||||
group_by: 'test'.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
expect { builder.summary }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
@@ -168,7 +168,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today - 2.days]).to be 5
|
||||
@@ -183,7 +183,7 @@ describe ::V2::ReportBuilder do
|
||||
until: (Time.zone.today + 1.day).to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 20
|
||||
@@ -199,7 +199,7 @@ describe ::V2::ReportBuilder do
|
||||
until: (Time.zone.today + 1.day).to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today]).to be 50
|
||||
@@ -217,7 +217,7 @@ describe ::V2::ReportBuilder do
|
||||
|
||||
conversations = account.conversations.where('created_at < ?', 1.day.ago)
|
||||
conversations.each(&:resolved!)
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
|
||||
expect(metrics[Time.zone.today - 2.days]).to be 5
|
||||
@@ -234,7 +234,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.timeseries
|
||||
expect(metrics[Time.zone.today].to_f).to be 0.15e1
|
||||
end
|
||||
@@ -247,7 +247,7 @@ describe ::V2::ReportBuilder do
|
||||
until: Time.zone.today.end_of_day.to_time.to_i.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.summary
|
||||
|
||||
expect(metrics[:conversations_count]).to be 5
|
||||
@@ -266,7 +266,7 @@ describe ::V2::ReportBuilder do
|
||||
group_by: 'week'.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
metrics = builder.summary
|
||||
|
||||
expect(metrics[:conversations_count]).to be 5
|
||||
@@ -285,7 +285,7 @@ describe ::V2::ReportBuilder do
|
||||
group_by: 'test'.to_s
|
||||
}
|
||||
|
||||
builder = V2::ReportBuilder.new(account, params)
|
||||
builder = described_class.new(account, params)
|
||||
expect { builder.summary }.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RoomChannel, type: :channel do
|
||||
RSpec.describe RoomChannel do
|
||||
let!(:contact_inbox) { create(:contact_inbox) }
|
||||
|
||||
before do
|
||||
|
||||
@@ -19,6 +19,6 @@ RSpec.context 'with valid schedule.yml' do
|
||||
end
|
||||
end
|
||||
# ensure that no duplicates exist
|
||||
assert_equal schedule_keys.uniq.count, schedule_keys.count
|
||||
expect(schedule_keys.count).to eq(schedule_keys.uniq.count)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'API Base', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).to eq(user.id)
|
||||
expect(json_response['email']).to eq(user.email)
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ RSpec.describe 'Contact Merge Action API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).to eq(base_contact.id)
|
||||
expected_params = { account: account, base_contact: base_contact, mergee_contact: mergee_contact }
|
||||
expect(ContactMergeAction).to have_received(:new).with(expected_params)
|
||||
|
||||
@@ -25,7 +25,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body).size).to eq(account.users.count)
|
||||
expect(response.parsed_body.size).to eq(account.users.count)
|
||||
end
|
||||
|
||||
it 'returns custom fields on agents if present' do
|
||||
@@ -36,7 +36,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data.first['custom_attributes']['test']).to eq('test')
|
||||
end
|
||||
end
|
||||
@@ -131,7 +131,7 @@ RSpec.describe 'Agents API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data['role']).to eq('administrator')
|
||||
expect(response_data['availability_status']).to eq('busy')
|
||||
expect(response_data['auto_offline']).to be(false)
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
expect(json_response['payload']['status']).to eql('draft')
|
||||
expect(json_response['payload']['position']).to be(3)
|
||||
@@ -58,7 +58,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
expect(json_response['payload']['status']).to eql('draft')
|
||||
expect(json_response['payload']['position']).to be(3)
|
||||
@@ -86,7 +86,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
|
||||
category = Article.find(json_response['payload']['id'])
|
||||
@@ -112,7 +112,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||
|
||||
category = Article.find(json_response['payload']['id'])
|
||||
@@ -146,7 +146,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
params: article_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['title']).to eql(article_params[:article][:title])
|
||||
expect(json_response['payload']['status']).to eql(article_params[:article][:status])
|
||||
expect(json_response['payload']['position']).to eql(article_params[:article][:position])
|
||||
@@ -190,7 +190,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
params: {}
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be 2
|
||||
end
|
||||
|
||||
@@ -202,7 +202,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
params: { category_slug: category.slug }
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be 2
|
||||
end
|
||||
|
||||
@@ -219,7 +219,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
params: { query: 'funny' }
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be 1
|
||||
expect(json_response['meta']['all_articles_count']).to be 2
|
||||
expect(json_response['meta']['articles_count']).to be 1
|
||||
@@ -235,7 +235,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article2.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['title']).to eq(article2.title)
|
||||
expect(json_response['payload']['id']).to eq(article2.id)
|
||||
@@ -251,11 +251,11 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{root_article.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['associated_articles'].length).to eq(2)
|
||||
associated_articles_ids = json_response['payload']['associated_articles'].map { |article| article['id'] }
|
||||
expect(associated_articles_ids).to match_array([child_article_1.id, child_article_2.id])
|
||||
associated_articles_ids = json_response['payload']['associated_articles'].pluck('id')
|
||||
expect(associated_articles_ids).to contain_exactly(child_article_1.id, child_article_2.id)
|
||||
expect(json_response['payload']['id']).to eq(root_article.id)
|
||||
end
|
||||
end
|
||||
@@ -272,7 +272,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
blob = JSON.parse(response.body)
|
||||
blob = response.parsed_body
|
||||
|
||||
expect(blob['file_url']).to be_present
|
||||
end
|
||||
|
||||
@@ -134,7 +134,7 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
blob = JSON.parse(response.body)
|
||||
blob = response.parsed_body
|
||||
|
||||
expect(blob['blob_key']).to be_present
|
||||
expect(blob['blob_id']).to be_present
|
||||
@@ -167,13 +167,13 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: { attachment: file_1 }
|
||||
|
||||
blob_1 = JSON.parse(response.body)
|
||||
blob_1 = response.parsed_body
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/automation_rules/attach_file",
|
||||
headers: administrator.create_new_auth_token,
|
||||
params: { attachment: file_2 }
|
||||
|
||||
blob_2 = JSON.parse(response.body)
|
||||
blob_2 = response.parsed_body
|
||||
|
||||
params[:actions] = [
|
||||
{
|
||||
|
||||
@@ -222,7 +222,7 @@ RSpec.describe 'Campaigns API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::Campaign.exists?(campaign.display_id)).to be false
|
||||
expect(Campaign.exists?(campaign.display_id)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)).to eq(account.canned_responses.as_json)
|
||||
expect(response.parsed_body).to eq(account.canned_responses.as_json)
|
||||
end
|
||||
|
||||
it 'returns all the canned responses the user searched for' do
|
||||
@@ -42,7 +42,7 @@ RSpec.describe 'Canned Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)).to eq(
|
||||
expect(response.parsed_body).to eq(
|
||||
[cr3, cr2, cr1].as_json
|
||||
)
|
||||
end
|
||||
|
||||
@@ -62,7 +62,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id)
|
||||
expect(json_response['payload']['related_categories'][1]['id']).to eql(related_category_2.id)
|
||||
@@ -107,7 +107,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eql('Locale should be unique in the category and portal')
|
||||
end
|
||||
|
||||
@@ -125,7 +125,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['message']).to eql("Slug can't be blank")
|
||||
end
|
||||
@@ -160,7 +160,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['name']).to eql(category_params[:category][:name])
|
||||
expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id)
|
||||
@@ -185,7 +185,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['name']).to eql(category.name)
|
||||
expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id)
|
||||
@@ -257,7 +257,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].count).to be(category_count + 1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,13 +4,13 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
|
||||
let(:account) { create(:account) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:twilio_client) { instance_double(::Twilio::REST::Client) }
|
||||
let(:twilio_client) { instance_double(Twilio::REST::Client) }
|
||||
let(:message_double) { double }
|
||||
let(:twilio_webhook_setup_service) { instance_double(::Twilio::WebhookSetupService) }
|
||||
let(:twilio_webhook_setup_service) { instance_double(Twilio::WebhookSetupService) }
|
||||
|
||||
before do
|
||||
allow(::Twilio::REST::Client).to receive(:new).and_return(twilio_client)
|
||||
allow(::Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service)
|
||||
allow(Twilio::REST::Client).to receive(:new).and_return(twilio_client)
|
||||
allow(Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service)
|
||||
allow(twilio_webhook_setup_service).to receive(:perform)
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['name']).to eq('SMS Channel')
|
||||
expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1342ed')
|
||||
@@ -71,7 +71,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1111ed')
|
||||
end
|
||||
@@ -99,7 +99,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['name']).to eq('SMS Channel')
|
||||
expect(json_response['phone_number']).to eq('+1234567890')
|
||||
@@ -124,7 +124,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['phone_number']).to eq('whatsapp:+1224466880')
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type:
|
||||
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload'].length).to eq 4
|
||||
end
|
||||
@@ -44,7 +44,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type:
|
||||
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload'].length).to eq 2
|
||||
end
|
||||
@@ -55,7 +55,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type:
|
||||
get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: unknown.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload'].length).to eq 0
|
||||
end
|
||||
|
||||
@@ -114,7 +114,7 @@ RSpec.describe 'Notes API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::Note.exists?(note.id)).to be false
|
||||
expect(Note.exists?(note.id)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['email']).to eq(contact.email)
|
||||
expect(response_body['payload'].first['contact_inboxes'].first['source_id']).to eq(contact_inbox.source_id)
|
||||
expect(response_body['payload'].first['contact_inboxes'].first['inbox']['name']).to eq(contact_inbox.inbox.name)
|
||||
@@ -47,7 +47,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['email']).to eq(contact.email)
|
||||
expect(response_body['payload'].first['contact_inboxes'].blank?).to be(true)
|
||||
end
|
||||
@@ -58,7 +58,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].last['id']).to eq(contact_4.id)
|
||||
expect(response_body['payload'].last['email']).to eq(contact_4.email)
|
||||
end
|
||||
@@ -69,7 +69,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['email']).to eq(contact_1.email)
|
||||
expect(response_body['payload'].first['id']).to eq(contact_1.id)
|
||||
expect(response_body['payload'].last['email']).to eq(contact_4.email)
|
||||
@@ -81,7 +81,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['email']).to eq(contact.email)
|
||||
expect(response_body['payload'].first['id']).to eq(contact.id)
|
||||
expect(response_body['payload'].last['email']).to eq(contact_4.email)
|
||||
@@ -94,7 +94,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['conversations_count']).to eq(contact.conversations.count)
|
||||
expect(response_body['payload'].first['last_seen_at']).present?
|
||||
end
|
||||
@@ -110,7 +110,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['meta']['count']).to eq(2)
|
||||
expect(response_body['payload'].pluck('email')).to include(contact_with_label1.email, contact_with_label2.email)
|
||||
end
|
||||
@@ -160,7 +160,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
post "/api/v1/accounts/#{account.id}/contacts/import",
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json_response['error']).to eq('File is blank')
|
||||
@@ -191,7 +191,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
end
|
||||
|
||||
it 'returns all contacts who are online' do
|
||||
allow(::OnlineStatusTracker).to receive(:get_available_contact_ids).and_return([contact.id])
|
||||
allow(OnlineStatusTracker).to receive(:get_available_contact_ids).and_return([contact.id])
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/contacts/active",
|
||||
headers: admin.create_new_auth_token,
|
||||
@@ -353,7 +353,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
# only the inboxes which agent has access to are shown
|
||||
expect(JSON.parse(response.body)['payload'].pluck('inbox').pluck('id')).to eq([twilio_whatsapp_inbox.id])
|
||||
expect(response.parsed_body['payload'].pluck('inbox').pluck('id')).to eq([twilio_whatsapp_inbox.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -383,7 +383,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
# custom attributes are updated
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload']['contact']['custom_attributes']).to eq({ 'test' => 'test', 'test1' => 'test1' })
|
||||
end
|
||||
|
||||
@@ -395,7 +395,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)')
|
||||
end
|
||||
|
||||
@@ -460,7 +460,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['attributes']).to include('email')
|
||||
expect(response.parsed_body['attributes']).to include('email')
|
||||
end
|
||||
|
||||
it 'prevents updating with an existing phone number' do
|
||||
@@ -472,7 +472,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['attributes']).to include('phone_number')
|
||||
expect(response.parsed_body['attributes']).to include('phone_number')
|
||||
end
|
||||
|
||||
it 'updates avatar' do
|
||||
@@ -517,7 +517,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
it 'deletes the contact for administrator user' do
|
||||
allow(::OnlineStatusTracker).to receive(:get_presence).and_return(false)
|
||||
allow(OnlineStatusTracker).to receive(:get_presence).and_return(false)
|
||||
delete "/api/v1/accounts/#{account.id}/contacts/#{contact.id}",
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
@@ -530,7 +530,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
end
|
||||
|
||||
it 'does not delete the contact if online' do
|
||||
allow(::OnlineStatusTracker).to receive(:get_presence).and_return(true)
|
||||
allow(OnlineStatusTracker).to receive(:get_presence).and_return(true)
|
||||
|
||||
delete "/api/v1/accounts/#{account.id}/contacts/#{contact.id}",
|
||||
headers: admin.create_new_auth_token
|
||||
@@ -591,7 +591,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
before do
|
||||
create(:contact, account: account)
|
||||
contact.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
|
||||
contact.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
||||
end
|
||||
|
||||
it 'delete contact avatar' do
|
||||
|
||||
@@ -26,7 +26,7 @@ RSpec.describe '/api/v1/accounts/:account_id/conversations/:conversation_id/dire
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['content_type']).to eq('image/png')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ RSpec.describe 'Conversation Messages API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['error']).to eq('Validation failed: Content is too long (maximum is 150000 characters)')
|
||||
end
|
||||
@@ -61,7 +61,7 @@ RSpec.describe 'Conversation Messages API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data['content_attributes']['external_created_at']).to eq time_stamp
|
||||
expect(conversation.messages.count).to eq(1)
|
||||
expect(conversation.messages.last.sender_id).to eq(agent_bot.id)
|
||||
|
||||
@@ -765,7 +765,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].first['file_type']).to eq('image')
|
||||
end
|
||||
|
||||
@@ -775,7 +775,7 @@ RSpec.describe 'Conversations API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['payload'].length).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body).first['feedback_message']).to eq(csat_survey_response.feedback_message)
|
||||
expect(response.parsed_body.first['feedback_message']).to eq(csat_survey_response.feedback_message)
|
||||
end
|
||||
|
||||
it 'filters csat responses based on a date range' do
|
||||
@@ -43,7 +43,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data.pluck('id')).to include(csat_3_days_ago.id)
|
||||
expect(response_data.pluck('id')).not_to include(csat_10_days_ago.id)
|
||||
end
|
||||
@@ -63,7 +63,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data.size).to eq 2
|
||||
end
|
||||
|
||||
@@ -104,7 +104,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data['total_count']).to eq 1
|
||||
expect(response_data['total_sent_messages_count']).to eq 0
|
||||
expect(response_data['ratings_count']).to eq({ '1' => 1 })
|
||||
@@ -123,7 +123,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data['total_count']).to eq 1
|
||||
expect(response_data['total_sent_messages_count']).to eq 0
|
||||
expect(response_data['ratings_count']).to eq({ '1' => 1 })
|
||||
@@ -144,7 +144,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data['total_count']).to eq 2
|
||||
expect(response_data['total_sent_messages_count']).to eq 0
|
||||
expect(response_data['ratings_count']).to eq({ '1' => 2 })
|
||||
|
||||
@@ -23,7 +23,7 @@ RSpec.describe 'Custom Attribute Definitions API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
|
||||
expect(response_body.count).to eq(2)
|
||||
expect(response_body.first['attribute_key']).to eq(custom_attribute_definition.attribute_key)
|
||||
@@ -86,7 +86,7 @@ RSpec.describe 'Custom Attribute Definitions API', type: :request do
|
||||
end.to change(CustomAttributeDefinition, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['attribute_key']).to eq 'developer_id'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Custom Filters API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body.first['name']).to eq(custom_filter.name)
|
||||
expect(response_body.first['query']).to eq(custom_filter.query)
|
||||
end
|
||||
@@ -74,7 +74,7 @@ RSpec.describe 'Custom Filters API', type: :request do
|
||||
end.to change(CustomFilter, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eq 'vip-customers'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'DashboardAppsController', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body.first['title']).to eq(dashboard_app.title)
|
||||
expect(response_body.first['content']).to eq(dashboard_app.content)
|
||||
end
|
||||
@@ -76,7 +76,7 @@ RSpec.describe 'DashboardAppsController', type: :request do
|
||||
end.to change(DashboardApp, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['title']).to eq 'CRM Dashboard'
|
||||
expect(json_response['content'][0]['link']).to eq payload[:dashboard_app][:content][0][:link]
|
||||
expect(json_response['content'][0]['type']).to eq payload[:dashboard_app][:content][0][:type]
|
||||
@@ -89,7 +89,7 @@ RSpec.describe 'DashboardAppsController', type: :request do
|
||||
end.not_to change(DashboardApp, :count)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eq 'Content : Invalid data'
|
||||
end
|
||||
|
||||
@@ -126,7 +126,7 @@ RSpec.describe 'DashboardAppsController', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(dashboard_app.reload.title).to eq('CRM Dashboard')
|
||||
expect(json_response['content'][0]['link']).to eq payload[:dashboard_app][:content][0][:link]
|
||||
expect(json_response['content'][0]['type']).to eq payload[:dashboard_app][:content][0][:type]
|
||||
|
||||
@@ -38,7 +38,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['payload'].pluck('id')).to eq(inbox.inbox_members.pluck(:user_id))
|
||||
expect(response.parsed_body['payload'].pluck('id')).to eq(inbox.inbox_members.pluck(:user_id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -248,7 +248,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
context 'when it is an authenticated user' do
|
||||
before do
|
||||
create(:inbox_member, user: agent, inbox: inbox)
|
||||
inbox.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
|
||||
inbox.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
||||
end
|
||||
|
||||
it 'delete inbox avatar for administrator user' do
|
||||
@@ -293,7 +293,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
as: :json
|
||||
end
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(json_response['message']).to eq('Your inbox deletion request will be processed in some time.')
|
||||
@@ -410,7 +410,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['allow_messages_after_resolved']).to be true
|
||||
end
|
||||
end
|
||||
@@ -452,7 +452,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
||||
expect(inbox.reload.portal_id).to eq(portal.id)
|
||||
expect(JSON.parse(response.body)['name']).to eq 'new test inbox'
|
||||
expect(response.parsed_body['name']).to eq 'new test inbox'
|
||||
end
|
||||
|
||||
it 'updates api inbox when administrator' do
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
apps = JSON.parse(response.body)['payload'].first
|
||||
apps = response.parsed_body['payload'].first
|
||||
expect(apps['id']).to eql(first_app.id)
|
||||
expect(apps['name']).to eql(first_app.name)
|
||||
expect(apps['action']).to be_nil
|
||||
@@ -36,7 +36,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
app = JSON.parse(response.body)['payload'].find { |int_app| int_app['id'] == openai.app.id }
|
||||
app = response.parsed_body['payload'].find { |int_app| int_app['id'] == openai.app.id }
|
||||
expect(app['hooks'].first['settings']).to be_nil
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
apps = JSON.parse(response.body)['payload'].first
|
||||
apps = response.parsed_body['payload'].first
|
||||
expect(apps['id']).to eql(first_app.id)
|
||||
expect(apps['name']).to eql(first_app.name)
|
||||
expect(apps['action']).to eql(first_app.action)
|
||||
@@ -60,7 +60,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
apps = JSON.parse(response.body)['payload']
|
||||
apps = response.parsed_body['payload']
|
||||
slack_app = apps.find { |app| app['id'] == 'slack' }
|
||||
expect(slack_app['action']).to include('client_id=client_id')
|
||||
end
|
||||
@@ -74,7 +74,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
app = JSON.parse(response.body)['payload'].find { |int_app| int_app['id'] == openai.app.id }
|
||||
app = response.parsed_body['payload'].find { |int_app| int_app['id'] == openai.app.id }
|
||||
expect(app['hooks'].first['settings']).not_to be_nil
|
||||
end
|
||||
end
|
||||
@@ -98,7 +98,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
app = JSON.parse(response.body)
|
||||
app = response.parsed_body
|
||||
expect(app['id']).to eql('slack')
|
||||
expect(app['name']).to eql('Slack')
|
||||
end
|
||||
@@ -111,7 +111,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
app = JSON.parse(response.body)
|
||||
app = response.parsed_body
|
||||
expect(app['hooks'].first['settings']).to be_nil
|
||||
end
|
||||
|
||||
@@ -123,7 +123,7 @@ RSpec.describe 'Integration Apps API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
app = JSON.parse(response.body)
|
||||
app = response.parsed_body
|
||||
expect(app['hooks'].first['settings']).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ RSpec.describe 'Dyte Integration API', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
last_message = conversation.reload.messages.last
|
||||
expect(conversation.display_id).to eq(response_body['conversation_id'])
|
||||
expect(last_message.id).to eq(response_body['id'])
|
||||
@@ -76,7 +76,7 @@ RSpec.describe 'Dyte Integration API', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['error']).to eq({ 'data' => { 'message' => 'Title is required' }, 'success' => false })
|
||||
end
|
||||
end
|
||||
@@ -126,7 +126,7 @@ RSpec.describe 'Dyte Integration API', type: :request do
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['authResponse']).to eq(
|
||||
{
|
||||
'userAdded' => true, 'id' => 'random_uuid', 'auth_token' => 'json-web-token'
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Integration Hooks API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['app_id']).to eq params[:app_id]
|
||||
end
|
||||
end
|
||||
@@ -71,7 +71,7 @@ RSpec.describe 'Integration Hooks API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['app_id']).to eq 'slack'
|
||||
end
|
||||
end
|
||||
@@ -131,7 +131,7 @@ RSpec.describe 'Integration Hooks API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::Integrations::Hook.exists?(hook.id)).to be false
|
||||
expect(Integrations::Hook.exists?(hook.id)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
visible_macros = account.macros.global.or(account.macros.personal.where(created_by_id: administrator.id)).order(:id)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
|
||||
expect(body['payload'].length).to eq(visible_macros.count)
|
||||
|
||||
@@ -42,7 +42,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
visible_macros = account.macros.global.or(account.macros.personal.where(created_by_id: agent.id)).order(:id)
|
||||
|
||||
expect(body['payload'].length).to eq(visible_macros.count)
|
||||
@@ -105,7 +105,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['name']).to eql(params['name'])
|
||||
expect(json_response['payload']['visibility']).to eql(params['visibility'])
|
||||
@@ -119,7 +119,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['name']).to eql(params['name'])
|
||||
expect(json_response['payload']['visibility']).to eql('personal')
|
||||
@@ -135,7 +135,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
blob = JSON.parse(response.body)
|
||||
blob = response.parsed_body
|
||||
|
||||
expect(blob['blob_key']).to be_present
|
||||
expect(blob['blob_id']).to be_present
|
||||
@@ -186,7 +186,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
headers: administrator.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eql(params['name'])
|
||||
end
|
||||
|
||||
@@ -197,7 +197,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
params: params,
|
||||
headers: agent_1.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
expect(json_response['error']).to eq('You are not authorized to do this action')
|
||||
@@ -223,7 +223,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['payload']['name']).to eql(macro.name)
|
||||
expect(json_response['payload']['created_by']['id']).to eql(administrator.id)
|
||||
@@ -242,7 +242,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
get "/api/v1/accounts/#{account.id}/macros/#{macro.id}",
|
||||
headers: agent_1.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
expect(json_response['error']).to eq('You are not authorized to do this action')
|
||||
@@ -452,7 +452,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
delete "/api/v1/accounts/#{account.id}/macros/#{macro.id}",
|
||||
headers: agent_1.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
expect(json_response['error']).to eq('You are not authorized to do this action')
|
||||
@@ -464,7 +464,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
||||
delete "/api/v1/accounts/#{account.id}/macros/#{macro.id}",
|
||||
headers: agent_1.create_new_auth_token
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
expect(json_response['error']).to eq('You are not authorized to do this action')
|
||||
|
||||
@@ -40,8 +40,8 @@ RSpec.describe 'Microsoft Authorization API', type: :request do
|
||||
prompt: 'consent'
|
||||
}
|
||||
)
|
||||
expect(JSON.parse(response.body)['url']).to eq response_url
|
||||
expect(::Redis::Alfred.get(administrator.email)).to eq(account.id.to_s)
|
||||
expect(response.parsed_body['url']).to eq response_url
|
||||
expect(Redis::Alfred.get(administrator.email)).to eq(account.id.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['user_id']).to eq(agent.id)
|
||||
expect(json_response['account_id']).to eq(account.id)
|
||||
end
|
||||
@@ -47,7 +47,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
agent.reload
|
||||
expect(json_response['user_id']).to eq(agent.id)
|
||||
expect(json_response['account_id']).to eq(account.id)
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Notifications API', type: :request do
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
response_json = JSON.parse(response.body)
|
||||
response_json = response.parsed_body
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(notification1.notification_type)
|
||||
expect(response_json['data']['meta']['unread_count']).to eq 2
|
||||
@@ -121,7 +121,7 @@ RSpec.describe 'Notifications API', type: :request do
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
response_json = JSON.parse(response.body)
|
||||
response_json = response.parsed_body
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response_json).to eq 2
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].length).to be 2
|
||||
expect(json_response['payload'][0]['id']).to be portal.id
|
||||
end
|
||||
@@ -48,7 +48,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eq portal.name
|
||||
expect(json_response['meta']['all_articles_count']).to eq 0
|
||||
end
|
||||
@@ -65,7 +65,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eq portal.name
|
||||
expect(json_response['meta']['all_articles_count']).to eq 2
|
||||
expect(json_response['meta']['mine_articles_count']).to eq 1
|
||||
@@ -98,7 +98,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eql('test_portal')
|
||||
expect(json_response['custom_domain']).to eql('support.chatwoot.dev')
|
||||
end
|
||||
@@ -130,7 +130,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eql(portal_params[:portal][:name])
|
||||
expect(json_response['config']).to eql({ 'allowed_locales' => [{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en' },
|
||||
{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }] })
|
||||
@@ -150,7 +150,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['archived']).to eql(portal_params[:portal][:archived])
|
||||
|
||||
portal.reload
|
||||
@@ -204,7 +204,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
headers: admin.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(portal.reload.member_ids).to include(agent_1.id)
|
||||
expect(json_response['portal_members'].length).to be(3)
|
||||
end
|
||||
@@ -221,7 +221,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
blob = JSON.parse(response.body)
|
||||
blob = response.parsed_body
|
||||
|
||||
expect(blob['blob_key']).to be_present
|
||||
expect(blob['blob_id']).to be_present
|
||||
|
||||
@@ -33,7 +33,7 @@ RSpec.describe 'Search', type: :request do
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
expect(response_data[:payload][:messages].first[:content]).to eq 'test2'
|
||||
expect(response_data[:payload].keys).to match_array [:contacts, :conversations, :messages]
|
||||
expect(response_data[:payload].keys).to contain_exactly(:contacts, :conversations, :messages)
|
||||
expect(response_data[:payload][:messages].length).to eq 2
|
||||
expect(response_data[:payload][:conversations].length).to eq 1
|
||||
expect(response_data[:payload][:contacts].length).to eq 1
|
||||
@@ -60,7 +60,7 @@ RSpec.describe 'Search', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
expect(response_data[:payload].keys).to match_array [:contacts]
|
||||
expect(response_data[:payload].keys).to contain_exactly(:contacts)
|
||||
expect(response_data[:payload][:contacts].length).to eq 1
|
||||
end
|
||||
end
|
||||
@@ -85,7 +85,7 @@ RSpec.describe 'Search', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
expect(response_data[:payload].keys).to match_array [:conversations]
|
||||
expect(response_data[:payload].keys).to contain_exactly(:conversations)
|
||||
expect(response_data[:payload][:conversations].length).to eq 1
|
||||
end
|
||||
end
|
||||
@@ -110,7 +110,7 @@ RSpec.describe 'Search', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
expect(response_data[:payload].keys).to match_array [:messages]
|
||||
expect(response_data[:payload].keys).to contain_exactly(:messages)
|
||||
expect(response_data[:payload][:messages].length).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body).first['id']).to eq(agent.id)
|
||||
expect(response.parsed_body.first['id']).to eq(agent.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -65,7 +65,7 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response.count).to eq(user_ids.count - 1)
|
||||
end
|
||||
end
|
||||
@@ -144,7 +144,7 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response.count).to eq(user_ids.count)
|
||||
end
|
||||
|
||||
@@ -157,7 +157,7 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['error']).to eq('Invalid User IDs')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Teams API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body).first['id']).to eq(account.teams.first.id)
|
||||
expect(response.parsed_body.first['id']).to eq(account.teams.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -45,7 +45,7 @@ RSpec.describe 'Teams API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['id']).to eq(team.id)
|
||||
expect(response.parsed_body['id']).to eq(team.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ RSpec.describe 'Twitter Authorization API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['url']).to include('test_token')
|
||||
expect(response.parsed_body['url']).to include('test_token')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['payload']['webhooks'].count).to eql account.webhooks.count
|
||||
expect(response.parsed_body['payload']['webhooks'].count).to eql account.webhooks.count
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -46,7 +46,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
expect(JSON.parse(response.body)['payload']['webhook']['url']).to eql 'https://hello.com'
|
||||
expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com'
|
||||
end
|
||||
|
||||
it 'throws error when invalid url provided' do
|
||||
@@ -55,7 +55,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Url is invalid'
|
||||
expect(response.parsed_body['message']).to eql 'Url is invalid'
|
||||
end
|
||||
|
||||
it 'throws error if subscription events are invalid' do
|
||||
@@ -64,7 +64,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events'
|
||||
expect(response.parsed_body['message']).to eql 'Subscriptions Invalid events'
|
||||
end
|
||||
|
||||
it 'throws error if subscription events are empty' do
|
||||
@@ -73,7 +73,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events'
|
||||
expect(response.parsed_body['message']).to eql 'Subscriptions Invalid events'
|
||||
end
|
||||
|
||||
it 'use default if subscription events are nil' do
|
||||
@@ -83,7 +83,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(
|
||||
JSON.parse(response.body)['payload']['webhook']['subscriptions']
|
||||
response.parsed_body['payload']['webhook']['subscriptions']
|
||||
).to eql %w[conversation_status_changed conversation_updated conversation_created contact_created contact_updated
|
||||
message_created message_updated webwidget_triggered]
|
||||
end
|
||||
@@ -107,7 +107,7 @@ RSpec.describe 'Webhooks API', type: :request do
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['payload']['webhook']['url']).to eql 'https://hello.com'
|
||||
expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -149,7 +149,7 @@ RSpec.describe 'Accounts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(JSON.parse(response.body)['cache_keys'].keys).to match_array(%w[label inbox team])
|
||||
expect(response.parsed_body['cache_keys'].keys).to match_array(%w[label inbox team])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -206,7 +206,7 @@ RSpec.describe 'Accounts API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['subscription_type']).to eq('browser_push')
|
||||
expect(json_response['subscription_attributes']['auth']).to eq('test')
|
||||
end
|
||||
@@ -53,7 +53,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).to eq(subscription.id)
|
||||
end
|
||||
|
||||
@@ -74,7 +74,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).to eq(subscription.id)
|
||||
expect(json_response['user_id']).to eq(agent.id)
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).to eq(agent.id)
|
||||
expect(json_response['email']).to eq(agent.email)
|
||||
expect(json_response['access_token']).to eq(agent.access_token.token)
|
||||
@@ -50,7 +50,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
agent.reload
|
||||
expect(json_response['id']).to eq(agent.id)
|
||||
expect(json_response['name']).to eq(agent.name)
|
||||
@@ -64,7 +64,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
agent.reload
|
||||
expect(json_response['id']).to eq(agent.id)
|
||||
expect(json_response['name']).to eq(agent.name)
|
||||
@@ -99,7 +99,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)')
|
||||
end
|
||||
|
||||
@@ -123,7 +123,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['ui_settings']['is_contact_sidebar_open']).to be(false)
|
||||
end
|
||||
end
|
||||
@@ -159,7 +159,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
before do
|
||||
agent.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
|
||||
agent.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
||||
end
|
||||
|
||||
it 'deletes the agent avatar' do
|
||||
@@ -191,7 +191,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(::OnlineStatusTracker.get_status(account.id, agent.id)).to eq('busy')
|
||||
expect(OnlineStatusTracker.get_status(account.id, agent.id)).to eq('busy')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -214,7 +214,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['accounts'].first['auto_offline']).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ RSpec.describe '/api/v1/widget/campaigns', type: :request do
|
||||
get '/api/v1/widget/campaigns', params: params
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response.length).to eq 1
|
||||
expect(json_response.pluck('id')).to include(campaign_1.display_id)
|
||||
expect(json_response.pluck('id')).not_to include(campaign_2.display_id)
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do
|
||||
let!(:contact) { create(:contact, account: account) }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
describe 'POST /api/v1/widget/config' do
|
||||
let(:params) { { website_token: web_widget.website_token } }
|
||||
@@ -28,7 +28,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do
|
||||
end.to change(Contact, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data.keys).to include(*response_keys)
|
||||
end
|
||||
end
|
||||
@@ -43,7 +43,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do
|
||||
end.not_to change(Contact, :count)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data.keys).to include(*response_keys)
|
||||
expect(response_data['contact']['pubsub_token']).to eq(contact_inbox.pubsub_token)
|
||||
end
|
||||
@@ -70,7 +70,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do
|
||||
end.to change(Contact, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_data = JSON.parse(response.body)
|
||||
response_data = response.parsed_body
|
||||
expect(response_data.keys).to include(*response_keys)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
let(:contact) { create(:contact, account: account, email: 'test@test.com', phone_number: '+745623239') }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
describe 'PATCH /api/v1/widget/contact' do
|
||||
let(:params) { { website_token: web_widget.website_token, identifier: 'test' } }
|
||||
@@ -47,7 +47,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
params: params.merge({ phone_number: '45623239' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
expect(body['phone_number']).to eq('+745623239')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
@@ -57,7 +57,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
params: params.merge({ phone_number: '+245623239' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
expect(body['phone_number']).to eq('+245623239')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
@@ -67,7 +67,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
params: params.merge({ email: 'test@' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
expect(body['email']).to eq('test@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
@@ -77,7 +77,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
params: params.merge({ email: 'test-1@test.com' }),
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
expect(body['email']).to eq('test-1@test.com')
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
@@ -101,7 +101,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
as: :json
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body = response.parsed_body
|
||||
expect(body['id']).not_to eq(contact.id)
|
||||
expect(body['widget_auth_token']).not_to be_nil
|
||||
expect(Contact.find(body['id']).contact_inboxes.first.hmac_verified?).to be(true)
|
||||
|
||||
@@ -8,9 +8,9 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
let(:second_session) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let!(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token_without_conversation) do
|
||||
::Widget::TokenService.new(payload: { source_id: second_session.source_id, inbox_id: web_widget.inbox.id }).generate_token
|
||||
Widget::TokenService.new(payload: { source_id: second_session.source_id, inbox_id: web_widget.inbox.id }).generate_token
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/widget/conversations' do
|
||||
@@ -23,7 +23,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['id']).to eq(conversation.display_id)
|
||||
expect(json_response['status']).to eq(conversation.status)
|
||||
@@ -35,7 +35,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||
|
||||
payload = { source_id: 'invalid source id', inbox_id: web_widget.inbox.id }
|
||||
token = ::Widget::TokenService.new(payload: payload).generate_token
|
||||
token = Widget::TokenService.new(payload: payload).generate_token
|
||||
get '/api/v1/widget/conversations',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
params: { website_token: web_widget.website_token },
|
||||
@@ -65,7 +65,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).not_to be_nil
|
||||
expect(json_response['contact']['email']).to eq 'contact-email@chatwoot.com'
|
||||
expect(json_response['contact']['phone_number']).to eq '+919745313456'
|
||||
@@ -89,7 +89,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).not_to be_nil
|
||||
expect(json_response['contact']['email']).to be_nil
|
||||
expect(json_response['contact']['name']).to eq 'alphy'
|
||||
@@ -116,7 +116,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['id']).not_to be_nil
|
||||
expect(json_response['contact']['email']).to eq existing_contact.email
|
||||
expect(json_response['contact']['name']).not_to eq 'contact-name'
|
||||
@@ -144,7 +144,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['contact']['phone_number']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/direct_uploads', type: :request do
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
describe 'POST /api/v1/widget/direct_uploads' do
|
||||
context 'when post request is made' do
|
||||
@@ -31,7 +31,7 @@ RSpec.describe '/api/v1/widget/direct_uploads', type: :request do
|
||||
headers: { 'X-Auth-Token' => token }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['content_type']).to eq('image/png')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/events', type: :request do
|
||||
let(:contact) { create(:contact, account: account) }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
describe 'POST /api/v1/widget/events' do
|
||||
let(:params) { { website_token: web_widget.website_token, name: 'webwidget.triggered', event_info: { test_id: 'test' } } }
|
||||
|
||||
@@ -19,7 +19,7 @@ RSpec.describe '/api/v1/widget/inbox_members', type: :request do
|
||||
get '/api/v1/widget/inbox_members', params: params
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].length).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:message) { create(:message, conversation: conversation, account: account, inbox: conversation.inbox) }
|
||||
let!(:integration_message) do
|
||||
create(:message, content_type: 'integrations',
|
||||
@@ -39,7 +39,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['error']).to eq('Invalid message type. Action not permitted')
|
||||
end
|
||||
end
|
||||
@@ -61,7 +61,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
response_body = JSON.parse(response.body)
|
||||
response_body = response.parsed_body
|
||||
expect(response_body['authResponse']).to eq(
|
||||
{
|
||||
'userAdded' => true, 'id' => 'random_uuid', 'auth_token' => 'json-web-token'
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/labels', type: :request do
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let!(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
describe 'POST /api/v1/widget/labels' do
|
||||
let(:params) { { website_token: web_widget.website_token, label: 'customer-support' } }
|
||||
|
||||
@@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) }
|
||||
let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) }
|
||||
let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } }
|
||||
let(:token) { ::Widget::TokenService.new(payload: payload).generate_token }
|
||||
let(:token) { Widget::TokenService.new(payload: payload).generate_token }
|
||||
|
||||
before do |example|
|
||||
2.times.each { create(:message, account: account, inbox: web_widget.inbox, conversation: conversation) } unless example.metadata[:skip_before]
|
||||
@@ -22,7 +22,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
# 2 messages created + 2 messages by the email hook
|
||||
expect(json_response['payload'].length).to eq(4)
|
||||
expect(json_response['meta']).not_to be_empty
|
||||
@@ -35,7 +35,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['payload'].length).to eq(0)
|
||||
end
|
||||
end
|
||||
@@ -52,7 +52,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['content']).to eq(message_params[:content])
|
||||
end
|
||||
|
||||
@@ -66,7 +66,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['message']).to eq('Content is too long (maximum is 150000 characters)')
|
||||
end
|
||||
@@ -79,7 +79,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do
|
||||
headers: { 'X-Auth-Token' => token }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['content']).to eq(message_params[:content])
|
||||
|
||||
expect(conversation.messages.last.attachments.first.file.present?).to be(true)
|
||||
|
||||
@@ -53,7 +53,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
current_day_metric = json_response.select { |x| x['timestamp'] == start_of_today }
|
||||
expect(current_day_metric.length).to eq(1)
|
||||
@@ -77,7 +77,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['open']).to eq(11)
|
||||
expect(json_response['unattended']).to eq(11)
|
||||
@@ -99,7 +99,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response.blank?).to be false
|
||||
user_metrics = json_response.find { |item| item['name'] == admin[:name] }
|
||||
expect(user_metrics.present?).to be true
|
||||
@@ -140,7 +140,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
user_metrics = json_response.find { |item| item['name'] == agent[:name] }
|
||||
expect(user_metrics.present?).to be true
|
||||
|
||||
@@ -184,7 +184,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['conversations_count']).to eq(10)
|
||||
end
|
||||
@@ -254,7 +254,7 @@ RSpec.describe 'Reports API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['conversations_count']).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
describe 'GET /installation/onboarding' do
|
||||
context 'when CHATWOOT_INSTALLATION_ONBOARDING redis key is not set' do
|
||||
it 'redirects back' do
|
||||
expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil
|
||||
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil
|
||||
get '/installation/onboarding'
|
||||
expect(response).to have_http_status(:redirect)
|
||||
end
|
||||
@@ -14,10 +14,10 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
|
||||
context 'when CHATWOOT_INSTALLATION_ONBOARDING redis key is set' do
|
||||
it 'returns onboarding page' do
|
||||
::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
get '/installation/onboarding'
|
||||
expect(response).to have_http_status(:success)
|
||||
::Redis::Alfred.delete(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,17 +29,17 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
allow(AccountBuilder).to receive(:new).and_return(account_builder)
|
||||
allow(account_builder).to receive(:perform).and_return(true)
|
||||
allow(ChatwootHub).to receive(:register_instance).and_return(true)
|
||||
::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true)
|
||||
end
|
||||
|
||||
after do
|
||||
::Redis::Alfred.delete(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
end
|
||||
|
||||
context 'when onboarding successfull' do
|
||||
it 'deletes the redis key' do
|
||||
post '/installation/onboarding', params: { user: {} }
|
||||
expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil
|
||||
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil
|
||||
end
|
||||
|
||||
it 'will not call register instance when checkboxes are unchecked' do
|
||||
@@ -57,7 +57,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do
|
||||
it 'does not deletes the redis key' do
|
||||
allow(AccountBuilder).to receive(:new).and_raise('error')
|
||||
post '/installation/onboarding', params: { user: {} }
|
||||
expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).not_to be_nil
|
||||
expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ RSpec.describe 'Platform Account Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['user_id']).to eq(user.id)
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ RSpec.describe 'Platform Account Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['role']).to eq('administrator')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ RSpec.describe 'Platform Accounts API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to eq('Test Account')
|
||||
expect(json_response['locale']).to eq('es')
|
||||
expect(json_response['features']['agent_management']).to be(true)
|
||||
@@ -59,7 +59,7 @@ RSpec.describe 'Platform Accounts API', type: :request do
|
||||
disable_branding: false
|
||||
} }, headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
expect(json_response['name']).to include('Test Account')
|
||||
expect(json_response['features']['inbox_management']).to be(true)
|
||||
expect(json_response['features']['ip_lookup']).to be(true)
|
||||
|
||||
@@ -24,7 +24,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do
|
||||
it 'returns unauthorized when its not a permissible object' do
|
||||
get '/platform/api/v1/agent_bots', headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data.length).to eq(0)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data.length).to eq(1)
|
||||
end
|
||||
end
|
||||
@@ -71,7 +71,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['name']).to eq(agent_bot.name)
|
||||
end
|
||||
end
|
||||
@@ -100,7 +100,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['name']).to eq('test')
|
||||
expect(platform_app.platform_app_permissibles.first.permissible_id).to eq data['id']
|
||||
end
|
||||
@@ -137,7 +137,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['name']).to eq('test123')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['email']).to eq(user.email)
|
||||
expect(data['custom_attributes']['test']).to eq('test')
|
||||
end
|
||||
@@ -70,7 +70,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['url']).to include('email=dev%2Btesting%40chatwoot.com&sso_auth_token=')
|
||||
end
|
||||
end
|
||||
@@ -103,7 +103,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
end.not_to enqueue_mail
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data).to match(
|
||||
hash_including(
|
||||
'name' => 'test',
|
||||
@@ -118,7 +118,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
|
||||
post '/platform/api/v1/users/', params: { name: 'test', email: 'TesT@test.com', password: 'Password1!' },
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['message']).to eq('Email has already been taken')
|
||||
end
|
||||
|
||||
@@ -128,7 +128,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['name']).to eq('old test')
|
||||
expect(platform_app.platform_app_permissibles.first.permissible_id).to eq data['id']
|
||||
end
|
||||
@@ -167,7 +167,7 @@ RSpec.describe 'Platform Users API', type: :request do
|
||||
headers: { api_access_token: platform_app.access_token.token }, as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['name']).to eq('test123')
|
||||
expect(data['email']).to eq('newtestemail@test.com')
|
||||
expect(data['custom_attributes']['test']).to eq('test_update')
|
||||
|
||||
@@ -6,7 +6,7 @@ RSpec.describe 'Public Survey Responses API', type: :request do
|
||||
conversation = create(:conversation)
|
||||
create(:message, conversation: conversation, content_type: 'input_csat')
|
||||
get "/public/api/v1/csat_survey/#{conversation.uuid}"
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(data['conversation_id']).to eq conversation.id
|
||||
end
|
||||
@@ -30,7 +30,7 @@ RSpec.describe 'Public Survey Responses API', type: :request do
|
||||
params: params,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['conversation_id']).to eq conversation.id
|
||||
expect(data['csat_survey_response']['conversation_id']).to eq conversation.id
|
||||
expect(data['csat_survey_response']['feedback_message']).to eq 'amazing experience'
|
||||
|
||||
@@ -11,7 +11,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do
|
||||
get "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations"
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data.length).to eq 1
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do
|
||||
post "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations"
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['id']).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
get "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations/#{conversation.display_id}/messages"
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data.length).to eq 2
|
||||
end
|
||||
end
|
||||
@@ -24,7 +24,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
params: { content: 'hello' }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['content']).to eq('hello')
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['message']).to eq('Content is too long (maximum is 150000 characters)')
|
||||
end
|
||||
@@ -46,7 +46,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
params: { content: 'hello', attachments: [file] }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['content']).to eq('hello')
|
||||
|
||||
expect(conversation.messages.last.attachments.first.file.present?).to be(true)
|
||||
@@ -62,7 +62,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
params: { submitted_values: [{ title: 'test' }] }
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['content_attributes']['submitted_values'].first['title']).to eq 'test'
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
data = JSON.parse(response.body)
|
||||
data = response.parsed_body
|
||||
expect(data['content_attributes']['submitted_values']['csat_survey_response']['feedback_message']).to eq 'amazing experience'
|
||||
expect(data['content_attributes']['submitted_values']['csat_survey_response']['rating']).to eq 4
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ RSpec.describe 'Public Portals API', type: :request do
|
||||
get "/hc/#{portal.slug}/en"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
json_response = JSON.parse(response.body)
|
||||
json_response = response.parsed_body
|
||||
|
||||
expect(json_response['error']).to eql "Domain: www.example.com is not registered with us. \
|
||||
Please send us an email at support@chatwoot.com with the custom domain name and account API key"
|
||||
|
||||
@@ -5,7 +5,7 @@ RSpec.describe 'Twilio::CallbacksController', type: :request do
|
||||
let(:twilio_service) { instance_double(Twilio::IncomingMessageService) }
|
||||
|
||||
before do
|
||||
allow(::Twilio::IncomingMessageService).to receive(:new).and_return(twilio_service)
|
||||
allow(Twilio::IncomingMessageService).to receive(:new).and_return(twilio_service)
|
||||
allow(twilio_service).to receive(:perform)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Twitter::CallbacksController', type: :request do
|
||||
let(:twitter_client) { instance_double(::Twitty::Facade) }
|
||||
let(:twitter_response) { instance_double(::Twitty::Response, status: '200', body: { message: 'Valid' }) }
|
||||
let(:twitter_client) { instance_double(Twitty::Facade) }
|
||||
let(:twitter_response) { instance_double(Twitty::Response, status: '200', body: { message: 'Valid' }) }
|
||||
let(:raw_response) { double }
|
||||
let(:user_object_rsponse) do
|
||||
OpenStruct.new(
|
||||
@@ -15,15 +15,15 @@ RSpec.describe 'Twitter::CallbacksController', type: :request do
|
||||
let(:webhook_service) { double }
|
||||
|
||||
before do
|
||||
allow(::Twitty::Facade).to receive(:new).and_return(twitter_client)
|
||||
allow(::Redis::Alfred).to receive(:get).and_return(account.id)
|
||||
allow(::Redis::Alfred).to receive(:delete).and_return('OK')
|
||||
allow(Twitty::Facade).to receive(:new).and_return(twitter_client)
|
||||
allow(Redis::Alfred).to receive(:get).and_return(account.id)
|
||||
allow(Redis::Alfred).to receive(:delete).and_return('OK')
|
||||
allow(twitter_client).to receive(:access_token).and_return(twitter_response)
|
||||
allow(twitter_response).to receive(:raw_response).and_return(raw_response)
|
||||
allow(raw_response).to receive(:body).and_return('oauth_token=1&oauth_token_secret=1&user_id=100&screen_name=chatwoot')
|
||||
allow(twitter_client).to receive(:user_show).and_return(user_object_rsponse)
|
||||
allow(JSON).to receive(:parse).and_return(user_object_rsponse)
|
||||
allow(::Twitter::WebhookSubscribeService).to receive(:new).and_return(webhook_service)
|
||||
allow(Twitter::WebhookSubscribeService).to receive(:new).and_return(webhook_service)
|
||||
end
|
||||
|
||||
describe 'GET /twitter/callback' do
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user