Fix tests for notifications [SCI-9678]

This commit is contained in:
Giga Chubinidze 2023-11-21 13:08:12 +04:00
parent 7a916b7d11
commit 94e2541de3
4 changed files with 4 additions and 70 deletions

View file

@ -2,11 +2,8 @@
FactoryBot.define do
factory :notification do
title do
'<i>Admin</i> was added as Owner to project ' \
'<strong>Demo project - qPCR</strong> by <i>User</i>.'
end
message { 'Project: <a href=\"/projects/3\"> Demo project - qPCR</a>' }
type_of { 'assignment' }
recipient_type { 'User' }
recipient_id { 1 }
read_at { Time.now }
end
end

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
FactoryBot.define do
factory :user_notification do
checked { false }
end
end

View file

@ -15,17 +15,11 @@ describe Notification, type: :model do
describe 'Database table' do
it { should have_db_column :id }
it { should have_db_column :title }
it { should have_db_column :message }
it { should have_db_column :type_of }
it { should have_db_column :generator_user_id }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
end
describe 'Relations' do
it { should belong_to(:generator_user).class_name('User').optional }
it { should have_many :users }
it { should have_many :user_notifications }
it { should belong_to(:recipient) }
end
end

View file

@ -1,50 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
describe UserNotification, type: :model do
let(:user) { create :user }
let(:user_notification) { build :user_notification }
it 'is valid' do
expect(user_notification).to be_valid
end
it 'should be of class UserNotification' do
expect(subject.class).to eq UserNotification
end
describe 'Database table' do
it { should have_db_column :user_id }
it { should have_db_column :notification_id }
it { should have_db_column :checked }
it { should have_db_column :created_at }
it { should have_db_column :updated_at }
end
describe 'Relations' do
it { should belong_to(:user).optional }
it { should belong_to(:notification).optional }
end
describe '#unseen_notification_count ' do
let(:notifcation) { create :notification }
it 'returns a number of unseen notifications' do
create :user_notification, user: user, notification: notifcation
expect(UserNotification.unseen_notification_count(user)).to eq 1
end
end
describe '#seen_by_user' do
let!(:notification) { create :notification }
let!(:user_notification_one) do
create :user_notification, user: user, notification: notification
end
it 'set the check status to false' do
expect do
UserNotification.seen_by_user(user)
end.to change { user_notification_one.reload.checked }.from(false).to(true)
end
end
end