mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Feature: User Notification Objects (#752)
Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
@@ -56,10 +56,10 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
let(:valid_params) { { contact: { account_id: account.id } } }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'creates the contact' do
|
||||
expect { post "/api/v1/accounts/#{account.id}/contacts", params: valid_params }.to change(Contact, :count).by(1)
|
||||
it 'returns unauthorized' do
|
||||
expect { post "/api/v1/accounts/#{account.id}/contacts", params: valid_params }.to change(Contact, :count).by(0)
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||
|
||||
it 'updates the email related notification flags' do
|
||||
put "/api/v1/accounts/#{account.id}/notification_settings",
|
||||
params: { notification_settings: { selected_email_flags: ['conversation_assignment'] } },
|
||||
params: { notification_settings: { selected_email_flags: ['email_conversation_assignment'] } },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
@@ -51,7 +51,7 @@ RSpec.describe 'Notification Settings API', type: :request do
|
||||
agent.reload
|
||||
expect(json_response['user_id']).to eq(agent.id)
|
||||
expect(json_response['account_id']).to eq(account.id)
|
||||
expect(json_response['selected_email_flags']).to eq(['conversation_assignment'])
|
||||
expect(json_response['selected_email_flags']).to eq(['email_conversation_assignment'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Notifications API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/notifications' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get "/api/v1/accounts/#{account.id}/notifications"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:notification) { create(:notification, account: account, user: admin) }
|
||||
|
||||
it 'returns all notifications' do
|
||||
get "/api/v1/accounts/#{account.id}/notifications",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(notification.notification_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /api/v1/accounts/{account.id}/notifications/:id' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let!(:notification) { create(:notification, account: account, user: admin) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
put "/api/v1/accounts/#{account.id}/notifications/#{notification.id}",
|
||||
params: { read_at: true }
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
|
||||
it 'updates the notification read at' do
|
||||
patch "/api/v1/accounts/#{account.id}/notifications/#{notification.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: { read_at: true },
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(notification.reload.read_at).not_to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Notifications Subscriptions API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
describe 'POST /api/v1/notification_subscriptions' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post '/api/v1/notification_subscriptions'
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
it 'creates a notification subscriptions' do
|
||||
post '/api/v1/notification_subscriptions',
|
||||
params: { notification_subscription: { subscription_type: 'browser_push', 'subscription_attributes': { test: 'test' } } },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['subscription_type']).to eq('browser_push')
|
||||
expect(json_response['subscription_attributes']).to eq({ 'test' => 'test' })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user