Add: #95 リストへの新着投稿通知 (#192)

* Add: テーブル定義、内部処理

* Add: 通知の定期削除処理、自動削除、テスト

* Add: Web画面の表示、設定

* Fix test
This commit is contained in:
KMY(雪あすか) 2023-10-31 08:59:31 +09:00 committed by GitHub
parent 2cc60253c4
commit f8280ca5d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 300 additions and 9 deletions

View file

@ -0,0 +1,6 @@
# frozen_string_literal: true
Fabricator(:list_status) do
list { Fabricate.build(:list) }
status
end

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Vacuum::ListStatusesVacuum do
subject { described_class.new }
describe '#perform' do
let!(:local_status_old) { Fabricate(:status, created_at: 2.days.ago) }
let!(:local_status_recent) { Fabricate(:status, created_at: 5.hours.ago) }
let!(:list_status_old) { Fabricate(:list_status, status: local_status_old, created_at: local_status_old.created_at) }
let!(:list_status_recent) { Fabricate(:list_status, status: local_status_recent, created_at: local_status_recent.created_at) }
before do
subject.perform
end
it 'deletes old list status' do
expect { list_status_old.reload }.to raise_error ActiveRecord::RecordNotFound
end
it 'does not delete recent status' do
expect { list_status_recent.reload }.to_not raise_error
end
it 'statuses are remain' do
expect { local_status_old }.to_not raise_error
end
end
end

View file

@ -19,6 +19,7 @@ RSpec.describe 'Lists' do
Fabricate(:list, account: user.account, title: 'second list', replies_policy: :list),
Fabricate(:list, account: user.account, title: 'third list', replies_policy: :none),
Fabricate(:list, account: user.account, title: 'fourth list', exclusive: true),
Fabricate(:list, account: user.account, title: 'fourth list', notify: true),
]
end
@ -30,6 +31,7 @@ RSpec.describe 'Lists' do
replies_policy: list.replies_policy,
exclusive: list.exclusive,
antennas: list.antennas,
notify: list.notify,
}
end
end
@ -67,6 +69,7 @@ RSpec.describe 'Lists' do
replies_policy: list.replies_policy,
exclusive: list.exclusive,
antennas: list.antennas,
notify: list.notify,
})
end
@ -149,6 +152,7 @@ RSpec.describe 'Lists' do
replies_policy: list.replies_policy,
exclusive: list.exclusive,
antennas: list.antennas,
notify: list.notify,
})
end

View file

@ -5,6 +5,10 @@ require 'rails_helper'
describe FeedInsertWorker do
subject { described_class.new }
def notify?(account, type, activity_id)
Notification.exists?(account: account, type: type, activity_id: activity_id)
end
describe 'perform' do
let(:follower) { Fabricate(:account) }
let(:status) { Fabricate(:status) }
@ -48,5 +52,43 @@ describe FeedInsertWorker do
expect(instance).to have_received(:push_to_home).with(follower, status, update: nil)
end
end
context 'with notification' do
it 'skips notification when unset' do
subject.perform(status.id, follower.id)
expect(notify?(follower, 'status', status.id)).to be false
end
it 'pushes notification when read status is set' do
Fabricate(:follow, account: follower, target_account: status.account, notify: true)
subject.perform(status.id, follower.id)
expect(notify?(follower, 'status', status.id)).to be true
end
it 'skips notification when the account is registered list but not notify' do
follower.follow!(status.account)
list = Fabricate(:list, account: follower)
Fabricate(:list_account, list: list, account: status.account)
subject.perform(status.id, list.id, 'list')
list_status = ListStatus.find_by(list: list, status: status)
expect(list_status).to be_nil
end
it 'pushes notification when the account is registered list' do
follower.follow!(status.account)
list = Fabricate(:list, account: follower, notify: true)
Fabricate(:list_account, list: list, account: status.account)
subject.perform(status.id, list.id, 'list')
list_status = ListStatus.find_by(list: list, status: status)
expect(list_status).to_not be_nil
expect(notify?(follower, 'list_status', list_status.id)).to be true
end
end
end
end