glitch-soc/spec/models/concerns/glitch/account_interactions_spec.rb
David Yip c17c07158a
Introduce Glitch::AccountRelationships (#193)
Where possible, it is a good idea to add new backend code in ways that
will minimize conflict with upstream changes.  We can't do that
everywhere, but we can move our custom methods to a module that won't
be modified upstream, and that's a start.

This commit also gets the block/mute note maps into
REST::RelationshipSerializer under the "block_notes" and "mute_notes"
keys.
2018-01-27 01:23:14 -06:00

79 lines
2.1 KiB
Ruby

require 'rails_helper'
describe Glitch::AccountInteractions do
let(:account) { Fabricate(:account, username: 'account') }
let(:account_id) { account.id }
let(:account_ids) { [account_id] }
let(:target_account) { Fabricate(:account, username: 'target') }
let(:target_account_id) { target_account.id }
let(:target_account_ids) { [target_account_id] }
describe '.mute_note_map' do
subject { Account.mute_note_map(target_account_ids, account_id) }
context 'account with Mute' do
before do
Fabricate(:mute, target_account: target_account, account: account).tap do |m|
m.create_note!(note: note) if note
end
end
context 'with a note' do
let(:note) { 'Too many jorts' }
it 'returns { target_account_id => "(a note)" }' do
is_expected.to eq(target_account_id => 'Too many jorts')
end
end
context 'with no associated note' do
let(:note) { nil }
it 'returns { target_account_id => nil }' do
is_expected.to eq(target_account_id => nil)
end
end
end
context 'account without Mute' do
it 'returns {}' do
is_expected.to eq({})
end
end
end
describe '.block_note_map' do
subject { Account.block_note_map(target_account_ids, account_id) }
context 'account with Block' do
before do
Fabricate(:block, target_account: target_account, account: account).tap do |m|
m.create_note!(note: note) if note
end
end
context 'with a note' do
let(:note) { 'Too many oats' }
it 'returns { target_account_id => "(a note)" }' do
is_expected.to eq(target_account_id => 'Too many oats')
end
end
context 'with no associated note' do
let(:note) { nil }
it 'returns { target_account_id => nil }' do
is_expected.to eq(target_account_id => nil)
end
end
end
context 'account without Block' do
it 'returns {}' do
is_expected.to eq({})
end
end
end
end