他サーバーからカスタム絵文字によるスタンプを受け取った時に、ライセンス情報を保存する+ついでにテスト (#65)
* Wip: スタンプを他サーバーから受信するテスト作成、カスタム絵文字にdomainプロパティを追加 * Wip: ドメインに関するイレギュラーな状況に対応 * Wip: 他のサーバーのカスタム絵文字を送信するときのID変更処理を追加 * Wip: カスタム絵文字のIDを判定する場所を変更 * Wip: カスタム絵文字のURIを返す処理を削除(不要) * Wip: 絵文字リアクション受け入れ処理リファクタリング * Wip: 外部へ送信するカスタム絵文字データにライセンス情報を追加、ライセンス情報の受信をテストに追加 * Wip: ドメインブロックのテストを追加 * Wip: ついでに通常のドメインブロックを追加
This commit is contained in:
parent
3ccf0d02c6
commit
f0fac9be8f
4 changed files with 273 additions and 16 deletions
|
@ -29,6 +29,225 @@ RSpec.describe ActivityPub::Activity::Like do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#perform when receive emoji reaction' do
|
||||
subject do
|
||||
described_class.new(json, sender).perform
|
||||
EmojiReaction.where(status: status)
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
|
||||
end
|
||||
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Like',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
object: ActivityPub::TagManager.instance.uri_for(status),
|
||||
content: content,
|
||||
tag: tag,
|
||||
}.with_indifferent_access
|
||||
end
|
||||
let(:content) { nil }
|
||||
let(:tag) { nil }
|
||||
|
||||
context 'with unicode emoji' do
|
||||
let(:content) { '😀' }
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq '😀'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom emoji' do
|
||||
let(:content) { ':tinking:' }
|
||||
let(:tag) do
|
||||
{
|
||||
id: 'https://example.com/aaa',
|
||||
type: 'Emoji',
|
||||
icon: {
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
name: 'tinking',
|
||||
license: 'Everyone but Ohagi',
|
||||
}
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq 'tinking'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(subject.first.custom_emoji).to_not be_nil
|
||||
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
|
||||
expect(subject.first.custom_emoji.domain).to eq 'example.com'
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
|
||||
it 'custom emoji license is saved' do
|
||||
expect(subject.first.custom_emoji.license).to eq 'Everyone but Ohagi'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom emoji and custom domain' do
|
||||
let(:content) { ':tinking:' }
|
||||
let(:tag) do
|
||||
{
|
||||
id: 'https://example.com/aaa',
|
||||
type: 'Emoji',
|
||||
domain: 'post.kmycode.net',
|
||||
icon: {
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
name: 'tinking',
|
||||
}
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq 'tinking'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(subject.first.custom_emoji).to_not be_nil
|
||||
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
|
||||
expect(subject.first.custom_emoji.domain).to eq 'post.kmycode.net'
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom emoji but invalid id' do
|
||||
let(:content) { ':tinking:' }
|
||||
let(:tag) do
|
||||
{
|
||||
id: 'aaa',
|
||||
type: 'Emoji',
|
||||
icon: {
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
name: 'tinking',
|
||||
}
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq 'tinking'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(subject.first.custom_emoji).to_not be_nil
|
||||
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
|
||||
expect(subject.first.custom_emoji.domain).to eq 'example.com'
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom emoji but local domain' do
|
||||
let(:content) { ':tinking:' }
|
||||
let(:tag) do
|
||||
{
|
||||
id: 'aaa',
|
||||
type: 'Emoji',
|
||||
domain: Rails.configuration.x.local_domain,
|
||||
icon: {
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
name: 'tinking',
|
||||
}
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq 'tinking'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(subject.first.custom_emoji).to_not be_nil
|
||||
expect(subject.first.custom_emoji.shortcode).to eq 'tinking'
|
||||
expect(subject.first.custom_emoji.domain).to be_nil
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with unicode emoji and reject_media enabled' do
|
||||
let(:content) { '😀' }
|
||||
|
||||
before do
|
||||
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_media: true)
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq '😀'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with custom emoji and reject_media enabled' do
|
||||
let(:content) { ':tinking:' }
|
||||
let(:tag) do
|
||||
{
|
||||
id: 'https://example.com/aaa',
|
||||
type: 'Emoji',
|
||||
icon: {
|
||||
url: 'http://example.com/emoji.png',
|
||||
},
|
||||
name: 'tinking',
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
Fabricate(:domain_block, domain: 'example.com', severity: :noop, reject_media: true)
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 0
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when emoji reaction is disabled' do
|
||||
let(:content) { '😀' }
|
||||
|
||||
before do
|
||||
Form::AdminSettings.new(enable_emoji_reaction: false).save
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 0
|
||||
expect(sender.favourited?(status)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when emoji reaction between other servers is disabled' do
|
||||
let(:recipient) { Fabricate(:account, domain: 'narrow.com', uri: 'https://narrow.com/') }
|
||||
let(:content) { '😀' }
|
||||
|
||||
before do
|
||||
Form::AdminSettings.new(receive_other_servers_emoji_reaction: false).save
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 0
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when emoji reaction between other servers is disabled but that status is local' do
|
||||
let(:content) { '😀' }
|
||||
|
||||
before do
|
||||
Form::AdminSettings.new(receive_other_servers_emoji_reaction: false).save
|
||||
end
|
||||
|
||||
it 'create emoji reaction' do
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.name).to eq '😀'
|
||||
expect(subject.first.account).to eq sender
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform when domain_block' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
|
@ -50,7 +269,7 @@ RSpec.describe ActivityPub::Activity::Like do
|
|||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a favourite from sender to status', pending: 'considering spec' do
|
||||
it 'does not create a favourite from sender to status' do
|
||||
expect(sender.favourited?(status)).to be false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue