feat: Business hour Inbox APIs (#1821)

* feat: Business hour Inbox APIs
This commit is contained in:
Sojan Jose
2021-02-23 12:11:15 +05:30
committed by GitHub
parent a3b0de63de
commit 0e721653e5
14 changed files with 86 additions and 23 deletions

View File

@@ -141,7 +141,18 @@ RSpec.describe 'Inboxes API', type: :request do
let(:admin) { create(:user, account: account, role: :administrator) }
let(:valid_params) { { enable_auto_assignment: false, channel: { website_url: 'test.com' } } }
it 'updates inbox' do
it 'will not update inbox for agent' do
agent = create(:user, account: account, role: :agent)
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
headers: agent.create_new_auth_token,
params: valid_params,
as: :json
expect(response).to have_http_status(:unauthorized)
end
it 'updates inbox when administrator' do
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
headers: admin.create_new_auth_token,
params: valid_params,
@@ -151,7 +162,7 @@ RSpec.describe 'Inboxes API', type: :request do
expect(inbox.reload.enable_auto_assignment).to be_falsey
end
it 'updates avatar' do
it 'updates avatar when administrator' do
# no avatar before upload
expect(inbox.avatar.attached?).to eq(false)
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
@@ -165,15 +176,19 @@ RSpec.describe 'Inboxes API', type: :request do
expect(inbox.avatar.attached?).to eq(true)
end
it 'will not update inbox for agent' do
agent = create(:user, account: account, role: :agent)
it 'updates working hours when administrator' do
params = {
working_hours: [{ 'day_of_week' => 0, 'open_hour' => 9, 'open_minutes' => 0, 'close_hour' => 17, 'close_minutes' => 0 }],
working_hours_enabled: true,
out_of_office_message: 'hello'
}
patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}",
headers: agent.create_new_auth_token,
params: valid_params,
as: :json
params: valid_params.merge(params),
headers: admin.create_new_auth_token
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(:success)
inbox.reload
expect(inbox.reload.weekly_schedule.find { |schedule| schedule['day_of_week'] == 0 }['open_hour']).to eq 9
end
end
end