Adicionar aba faturamento em Reserv
This commit is contained in:
parent
389cbcbb61
commit
14dbc0f423
@ -13,7 +13,7 @@ class Api::V1::Accounts::Captain::UnitsController < Api::V1::Accounts::BaseContr
|
||||
|
||||
def create
|
||||
@unit = Current.account.captain_units.build(unit_params)
|
||||
@unit.captain_brand_id ||= Captain::Brand.where(account_id: Current.account.id).first&.id
|
||||
@unit.captain_brand_id ||= default_brand.id
|
||||
ActiveRecord::Base.transaction do
|
||||
@unit.save!
|
||||
sync_inbox_link!(@unit)
|
||||
@ -44,6 +44,14 @@ class Api::V1::Accounts::Captain::UnitsController < Api::V1::Accounts::BaseContr
|
||||
# Dependendo da regra de negócio, pode-se verificar as features da conta aqui original
|
||||
end
|
||||
|
||||
def default_brand
|
||||
@default_brand ||= Captain::Brand.where(account_id: Current.account.id).first ||
|
||||
Captain::Brand.create!(
|
||||
account_id: Current.account.id,
|
||||
name: 'Marca padrão'
|
||||
)
|
||||
end
|
||||
|
||||
def set_unit
|
||||
@unit = Current.account.captain_units.find(params[:id])
|
||||
end
|
||||
|
||||
@ -133,8 +133,11 @@ export default {
|
||||
this.$router.push({ name: 'captain_settings_units' });
|
||||
} catch (error) {
|
||||
const action = this.isNew ? 'ADD' : 'EDIT';
|
||||
const apiError =
|
||||
error?.response?.data?.errors?.join(' | ') ||
|
||||
error?.response?.data?.message;
|
||||
useAlert(
|
||||
error?.response?.data?.message ||
|
||||
apiError ||
|
||||
// eslint-disable-next-line
|
||||
this.$t(`CAPTAIN_SETTINGS.UNITS.${action}.API.ERROR_MESSAGE`)
|
||||
);
|
||||
|
||||
@ -53,5 +53,31 @@ RSpec.describe 'Api::V1::Accounts::Captain::Units', type: :request do
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.parsed_body['errors'].join).to match(/só pode ser habilitado/i)
|
||||
end
|
||||
|
||||
it 'creates a default brand automatically when account has no captain brand' do
|
||||
account_with_no_brand = create(:account)
|
||||
admin_without_brand = create(:user, account: account_with_no_brand, role: :administrator)
|
||||
|
||||
params = {
|
||||
captain_unit: {
|
||||
name: 'Hotel Sem Marca',
|
||||
inter_client_id: 'cid',
|
||||
inter_client_secret: 'csecret',
|
||||
inter_pix_key: '12345678901',
|
||||
inter_account_number: '210339349'
|
||||
}
|
||||
}
|
||||
|
||||
expect(Captain::Brand.where(account_id: account_with_no_brand.id).count).to eq(0)
|
||||
|
||||
post "/api/v1/accounts/#{account_with_no_brand.id}/captain/units",
|
||||
params: params,
|
||||
headers: admin_without_brand.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
brands = Captain::Brand.where(account_id: account_with_no_brand.id)
|
||||
expect(brands.count).to eq(1)
|
||||
expect(Captain::Unit.last.captain_brand_id).to eq(brands.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user