2017-04-17 23:07:46 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
RSpec.describe OStatus::AtomSerializer do
|
2017-06-03 18:51:08 +00:00
|
|
|
shared_examples 'follow request salmon' do
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
follow_request = Fabricate(:follow_request, account: account)
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
|
|
|
|
expect(follow_request_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
|
|
|
|
object_type = follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with request_friend type' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
|
|
|
|
verb = follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:request_friend]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object with target account' do
|
|
|
|
target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
|
|
|
|
follow_request = Fabricate(:follow_request, target_account: target_account)
|
|
|
|
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
|
|
|
|
object = follow_request_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
expect(object.id.text).to eq 'https://domain/id'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'namespaces' do
|
|
|
|
it 'adds namespaces' do
|
|
|
|
element = serialize
|
|
|
|
|
|
|
|
expect(element['xmlns']).to eq TagManager::XMLNS
|
|
|
|
expect(element['xmlns:thr']).to eq TagManager::THR_XMLNS
|
|
|
|
expect(element['xmlns:activity']).to eq TagManager::AS_XMLNS
|
|
|
|
expect(element['xmlns:poco']).to eq TagManager::POCO_XMLNS
|
|
|
|
expect(element['xmlns:media']).to eq TagManager::MEDIA_XMLNS
|
|
|
|
expect(element['xmlns:ostatus']).to eq TagManager::OS_XMLNS
|
|
|
|
expect(element['xmlns:mastodon']).to eq TagManager::MTDN_XMLNS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'no namespaces' do
|
|
|
|
it 'does not add namespaces' do
|
|
|
|
expect(serialize['xmlns']).to eq nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'status attributes' do
|
|
|
|
it 'appends summary element with spoiler text if present' do
|
|
|
|
status = Fabricate(:status, language: :ca, spoiler_text: 'spoiler text')
|
|
|
|
|
|
|
|
element = serialize(status)
|
|
|
|
|
|
|
|
summary = element.summary
|
|
|
|
expect(summary['xml:lang']).to eq 'ca'
|
|
|
|
expect(summary.text).to eq 'spoiler text'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append summary element with spoiler text if not present' do
|
|
|
|
status = Fabricate(:status, spoiler_text: '')
|
|
|
|
element = serialize(status)
|
|
|
|
element.nodes.each { |node| expect(node.name).not_to eq 'summary' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends content element with formatted status' do
|
|
|
|
status = Fabricate(:status, language: :ca, text: 'text')
|
|
|
|
|
|
|
|
element = serialize(status)
|
|
|
|
|
|
|
|
content = element.content
|
|
|
|
expect(content[:type]).to eq 'html'
|
|
|
|
expect(content['xml:lang']).to eq 'ca'
|
|
|
|
expect(content.text).to eq '<p>text</p>'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link elements for mentioned accounts' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status)
|
|
|
|
Fabricate(:mention, account: account, status: status)
|
|
|
|
|
|
|
|
element = serialize(status)
|
|
|
|
|
|
|
|
mentioned = element.nodes.find do |node|
|
|
|
|
node.name == 'link' &&
|
2017-09-19 00:42:40 +00:00
|
|
|
node[:rel] == 'mentioned' &&
|
|
|
|
node['ostatus:object-type'] == TagManager::TYPES[:person]
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
2017-09-19 00:42:40 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(mentioned[:href]).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
2017-09-19 00:42:40 +00:00
|
|
|
|
|
|
|
it 'appends link elements for emojis' do
|
|
|
|
Fabricate(:custom_emoji)
|
|
|
|
|
|
|
|
status = Fabricate(:status, text: ':coolcat:')
|
|
|
|
element = serialize(status)
|
|
|
|
emoji = element.nodes.find { |node| node.name == 'link' && node[:rel] == 'emoji' }
|
|
|
|
|
|
|
|
expect(emoji[:name]).to eq 'coolcat'
|
|
|
|
expect(emoji[:href]).to_not be_blank
|
|
|
|
end
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'render' do
|
|
|
|
it 'returns XML with emojis' do
|
|
|
|
element = Ox::Element.new('tag')
|
|
|
|
element << '💩'
|
2017-07-18 23:37:26 +00:00
|
|
|
xml = OStatus::AtomSerializer.render(element)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(xml).to eq "<?xml version=\"1.0\"?>\n<tag>💩</tag>\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns XML, stripping invalid characters like \b and \v' do
|
|
|
|
element = Ox::Element.new('tag')
|
|
|
|
element << "im l33t\b haxo\b\vr"
|
2017-07-18 23:37:26 +00:00
|
|
|
xml = OStatus::AtomSerializer.render(element)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(xml).to eq "<?xml version=\"1.0\"?>\n<tag>im l33t haxor</tag>\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#author' do
|
|
|
|
context 'when note is present' do
|
|
|
|
it 'appends poco:note element with note for local account' do
|
|
|
|
account = Fabricate(:account, domain: nil, note: '<p>note</p>')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
note = author.nodes.find { |node| node.name == 'poco:note' }
|
|
|
|
expect(note.text).to eq '<p>note</p>'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends poco:note element with tags-stripped note for remote account' do
|
|
|
|
account = Fabricate(:account, domain: 'remote', note: '<p>note</p>')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
note = author.nodes.find { |node| node.name == 'poco:note' }
|
|
|
|
expect(note.text).to eq 'note'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends summary element with type attribute and simplified note if present' do
|
|
|
|
account = Fabricate(:account, note: 'note')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(author.summary.text).to eq '<p>note</p>'
|
|
|
|
expect(author.summary[:type]).to eq 'html'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when note is not present' do
|
|
|
|
it 'does not append poco:note element' do
|
|
|
|
account = Fabricate(:account, note: '')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
author.nodes.each { |node| expect(node.name).not_to eq 'poco:note' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append summary element' do
|
|
|
|
account = Fabricate(:account, note: '')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
author.nodes.each { |node| expect(node.name).not_to eq 'summary' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns author element' do
|
|
|
|
account = Fabricate(:account)
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(author.name).to eq 'author'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with person type' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = author.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:person]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends email element with username and domain for local account' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(author.email.text).to eq 'username@cb6e6126.ngrok.io'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends email element with username and domain for remote user' do
|
|
|
|
account = Fabricate(:account, domain: 'domain', username: 'username')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(author.email.text).to eq 'username@domain'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for an alternative' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-08-17 23:03:18 +00:00
|
|
|
link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' && node[:type] == 'text/html' }
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(link[:type]).to eq 'text/html'
|
|
|
|
expect(link[:rel]).to eq 'alternate'
|
|
|
|
expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/@username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has link element for avatar if present' do
|
|
|
|
account = Fabricate(:account, avatar: attachment_fixture('avatar.gif'))
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'avatar' }
|
|
|
|
expect(link[:type]).to eq 'image/gif'
|
|
|
|
expect(link['media:width']).to eq '120'
|
|
|
|
expect(link['media:height']).to eq '120'
|
|
|
|
expect(link[:href]).to match /^https:\/\/cb6e6126.ngrok.io\/system\/accounts\/avatars\/.+\/original\/avatar.gif/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not have link element for avatar if not present' do
|
|
|
|
account = Fabricate(:account, avatar: nil)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
author.nodes.each do |node|
|
|
|
|
expect(node[:rel]).not_to eq 'avatar' if node.name == 'link'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for header if present' do
|
|
|
|
account = Fabricate(:account, header: attachment_fixture('avatar.gif'))
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = author.nodes.find { |node| node.name == 'link' && node[:rel] == 'header' }
|
|
|
|
expect(link[:type]).to eq 'image/gif'
|
|
|
|
expect(link['media:width']).to eq '700'
|
|
|
|
expect(link['media:height']).to eq '335'
|
|
|
|
expect(link[:href]).to match /^https:\/\/cb6e6126.ngrok.io\/system\/accounts\/headers\/.+\/original\/avatar.gif/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append link element for header if not present' do
|
|
|
|
account = Fabricate(:account, header: nil)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
author.nodes.each do |node|
|
|
|
|
expect(node[:rel]).not_to eq 'header' if node.name == 'link'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends poco:displayName element with display name if present' do
|
|
|
|
account = Fabricate(:account, display_name: 'display name')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
display_name = author.nodes.find { |node| node.name == 'poco:displayName' }
|
|
|
|
expect(display_name.text).to eq 'display name'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append poco:displayName element with display name if not present' do
|
|
|
|
account = Fabricate(:account, display_name: '')
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
author.nodes.each { |node| expect(node.name).not_to eq 'poco:displayName' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "appends mastodon:scope element with 'private' if locked" do
|
|
|
|
account = Fabricate(:account, locked: true)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
scope = author.nodes.find { |node| node.name == 'mastodon:scope' }
|
|
|
|
expect(scope.text).to eq 'private'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "appends mastodon:scope element with 'public' if unlocked" do
|
|
|
|
account = Fabricate(:account, locked: false)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
scope = author.nodes.find { |node| node.name == 'mastodon:scope' }
|
|
|
|
expect(scope.text).to eq 'public'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes URI' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
expect(author.uri.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes username' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
author = OStatus::AtomSerializer.new.author(account)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
name = author.nodes.find { |node| node.name == 'name' }
|
|
|
|
username = author.nodes.find { |node| node.name == 'poco:preferredUsername' }
|
|
|
|
expect(name.text).to eq 'username'
|
|
|
|
expect(username.text).to eq 'username'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#entry' do
|
|
|
|
shared_examples 'not root' do
|
|
|
|
include_examples 'no namespaces' do
|
|
|
|
def serialize
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append author element' do
|
|
|
|
subject.nodes.each { |node| expect(node.name).not_to eq 'author' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'it is root' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
stream_entry = Fabricate(:stream_entry)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.entry(stream_entry, true)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry, true)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if status is present' do
|
|
|
|
include_examples 'status attributes' do
|
|
|
|
def serialize(status)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.entry(status.stream_entry, true)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for the public collection if status is publicly visible' do
|
|
|
|
status = Fabricate(:status, visibility: :public)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
mentioned_person = entry.nodes.find do |node|
|
|
|
|
node.name == 'link' &&
|
|
|
|
node[:rel] == 'mentioned' &&
|
|
|
|
node['ostatus:object-type'] == TagManager::TYPES[:collection]
|
|
|
|
end
|
|
|
|
expect(mentioned_person[:href]).to eq TagManager::COLLECTIONS[:public]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append link element for the public collection if status is not publicly visible' do
|
|
|
|
status = Fabricate(:status, visibility: :private)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
entry.nodes.each do |node|
|
|
|
|
if node.name == 'link' &&
|
|
|
|
node[:rel] == 'mentioned' &&
|
|
|
|
node['ostatus:object-type'] == TagManager::TYPES[:collection]
|
|
|
|
expect(mentioned_collection[:href]).not_to eq TagManager::COLLECTIONS[:public]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends category elements for tags' do
|
|
|
|
tag = Fabricate(:tag, name: 'tag')
|
|
|
|
status = Fabricate(:status, tags: [ tag ])
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(entry.category[:term]).to eq 'tag'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends category element for NSFW if status is sensitive' do
|
|
|
|
status = Fabricate(:status, sensitive: true)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(entry.category[:term]).to eq 'nsfw'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link elements for media attachments' do
|
|
|
|
file = attachment_fixture('attachment.jpg')
|
|
|
|
media_attachment = Fabricate(:media_attachment, file: file)
|
|
|
|
status = Fabricate(:status, media_attachments: [ media_attachment ])
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
enclosure = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'enclosure' }
|
|
|
|
expect(enclosure[:type]).to eq 'image/jpeg'
|
|
|
|
expect(enclosure[:href]).to match /^https:\/\/cb6e6126.ngrok.io\/system\/media_attachments\/files\/.+\/original\/attachment.jpg$/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends mastodon:scope element with visibility' do
|
|
|
|
status = Fabricate(:status, visibility: :public)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
scope = entry.nodes.find { |node| node.name == 'mastodon:scope' }
|
|
|
|
expect(scope.text).to eq 'public'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns element whose rendered view triggers creation when processed' do
|
|
|
|
remote_account = Account.create!(username: 'username')
|
2017-09-06 17:01:28 +00:00
|
|
|
remote_status = Fabricate(:status, account: remote_account, created_at: '2000-01-01T00:00:00Z')
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(remote_status.stream_entry, true)
|
2017-08-17 23:03:18 +00:00
|
|
|
entry.nodes.delete_if { |node| node[:type] == 'application/activity+json' } # Remove ActivityPub link to simplify test
|
2017-07-18 23:37:26 +00:00
|
|
|
xml = OStatus::AtomSerializer.render(entry).gsub('cb6e6126.ngrok.io', 'remote')
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
remote_status.destroy!
|
|
|
|
remote_account.destroy!
|
|
|
|
|
|
|
|
account = Account.create!(
|
|
|
|
domain: 'remote',
|
|
|
|
username: 'username',
|
2017-08-17 23:03:18 +00:00
|
|
|
last_webfingered_at: Time.now.utc
|
2017-06-03 18:51:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ProcessFeedService.new.call(xml, account)
|
|
|
|
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(Status.find_by(uri: "https://remote/users/#{remote_status.account.to_param}/statuses/#{remote_status.id}")).to be_instance_of Status
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if status is not present' do
|
|
|
|
it 'appends content element saying status is deleted' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
status.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(entry.content.text).to eq 'Deleted status'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element saying the status is deleted' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
status.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(entry.title.text).to eq 'username deleted status'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'it is not root' do
|
|
|
|
let(:stream_entry) { Fabricate(:stream_entry) }
|
2017-07-18 23:37:26 +00:00
|
|
|
subject { OStatus::AtomSerializer.new.entry(stream_entry, false) }
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'not root'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without root parameter' do
|
|
|
|
let(:stream_entry) { Fabricate(:stream_entry) }
|
2017-07-18 23:37:26 +00:00
|
|
|
subject { OStatus::AtomSerializer.new.entry(stream_entry) }
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'not root'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
stream_entry = Fabricate(:stream_entry)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(entry.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
2017-09-06 17:01:28 +00:00
|
|
|
status = Fabricate(:status, reblog_of_id: nil, created_at: '2000-01-01T00:00:00Z')
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(entry.id.text).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends published element with created date' do
|
|
|
|
stream_entry = Fabricate(:stream_entry, created_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(entry.published.text).to eq '2000-01-01T00:00:00Z'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends updated element with updated date' do
|
|
|
|
stream_entry = Fabricate(:stream_entry, updated_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(entry.updated.text).to eq '2000-01-01T00:00:00Z'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with status title' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account, reblog_of_id: nil)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(entry.title.text).to eq 'New status by username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with object type' do
|
|
|
|
status = Fabricate(:status)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
object_type = entry.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:note]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with object type' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = entry.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(object_type.text).to eq TagManager::VERBS[:post]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with target if present' do
|
|
|
|
reblogged = Fabricate(:status, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
reblog = Fabricate(:status, reblog: reblogged)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(reblog.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = entry.nodes.find { |node| node.name == 'activity:object' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(object.id.text).to eq "https://cb6e6126.ngrok.io/users/#{reblogged.account.to_param}/statuses/#{reblogged.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append activity:object element if target is not present' do
|
|
|
|
status = Fabricate(:status, reblog_of_id: nil)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
entry.nodes.each { |node| expect(node.name).not_to eq 'activity:object' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for an alternative' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-08-17 23:03:18 +00:00
|
|
|
link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' && node[:type] == 'text/html' }
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(link[:type]).to eq 'text/html'
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(link[:href]).to eq "https://cb6e6126.ngrok.io/@username/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for itself' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' }
|
|
|
|
expect(link[:type]).to eq 'application/atom+xml'
|
|
|
|
expect(link[:href]).to eq "https://cb6e6126.ngrok.io/users/username/updates/#{status.stream_entry.id}.atom"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends thr:in-reply-to element if threaded' do
|
|
|
|
in_reply_to_status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reblog_of_id: nil)
|
|
|
|
reply_status = Fabricate(:status, in_reply_to_id: in_reply_to_status.id)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(reply_status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(in_reply_to[:ref]).to eq "https://cb6e6126.ngrok.io/users/#{in_reply_to_status.account.to_param}/statuses/#{in_reply_to_status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append thr:in-reply-to element if not threaded' do
|
|
|
|
status = Fabricate(:status)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends ostatus:conversation if conversation id is present' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
status.conversation.update!(created_at: '2000-01-01T00:00:00Z')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' }
|
|
|
|
expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation_id}:objectType=Conversation"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append ostatus:conversation if conversation id is not present' do
|
|
|
|
status = Fabricate.build(:status, conversation_id: nil)
|
|
|
|
status.save!(validate: false)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.entry(status.stream_entry)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' }
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
describe '#feed' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
account = Fabricate(:account)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns feed element' do
|
|
|
|
account = Fabricate(:account)
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.name).to eq 'feed'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with account Atom URL' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.id.text).to eq 'https://cb6e6126.ngrok.io/users/username.atom'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with account display name if present' do
|
|
|
|
account = Fabricate(:account, display_name: 'display name')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.title.text).to eq 'display name'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append title element with account username if account display name is not present' do
|
|
|
|
account = Fabricate(:account, display_name: '', username: 'username')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.title.text).to eq 'username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends subtitle element with account note' do
|
|
|
|
account = Fabricate(:account, note: 'note')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.subtitle.text).to eq 'note'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends updated element with date account got updated' do
|
|
|
|
account = Fabricate(:account, updated_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.updated.text).to eq '2000-01-01T00:00:00Z'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends logo element with full asset URL for original account avatar' do
|
|
|
|
account = Fabricate(:account, avatar: attachment_fixture('avatar.gif'))
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.logo.text).to match /^https:\/\/cb6e6126.ngrok.io\/system\/accounts\/avatars\/.+\/original\/avatar.gif/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(feed.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for an alternative' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-08-17 23:03:18 +00:00
|
|
|
link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' && node[:type] == 'text/html' }
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(link[:type]).to eq 'text/html'
|
|
|
|
expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/@username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for itself' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'self' }
|
|
|
|
expect(link[:type]).to eq 'application/atom+xml'
|
|
|
|
expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/users/username.atom'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for the next if it has 20 stream entries' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
stream_entry = Fabricate(:stream_entry)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, Array.new(20, stream_entry))
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'next' }
|
|
|
|
expect(link[:type]).to eq 'application/atom+xml'
|
|
|
|
expect(link[:href]).to eq "https://cb6e6126.ngrok.io/users/username.atom?max_id=#{stream_entry.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append link element for the next if it does not have 20 stream entries' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
feed.nodes.each do |node|
|
|
|
|
expect(node[:rel]).not_to eq 'next' if node.name == 'link'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for hub' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'hub' }
|
|
|
|
expect(link[:href]).to eq 'https://cb6e6126.ngrok.io/api/push'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for Salmon' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
link = feed.nodes.find { |node| node.name == 'link' && node[:rel] == 'salmon' }
|
|
|
|
expect(link[:href]).to start_with 'https://cb6e6126.ngrok.io/api/salmon/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends stream entries' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
feed = OStatus::AtomSerializer.new.feed(account, [status.stream_entry])
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(feed.entry.title.text).to eq 'New status by username'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#block_salmon' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(block_salmon.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
block = Fabricate(:block)
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(block_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
|
|
|
|
.or(eq(TagManager.instance.unique_tag(time_after.utc, block.id, 'Block')))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
block = Fabricate(:block, account: account, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(block_salmon.title.text).to eq 'account no longer wishes to interact with target_account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
block = Fabricate(:block, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-04-17 23:07:46 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(block_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account'
|
2017-04-17 23:07:46 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
block = Fabricate(:block)
|
2017-04-17 23:07:46 +00:00
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = block_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
2017-04-17 23:07:46 +00:00
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:verb element with block' do
|
|
|
|
block = Fabricate(:block)
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = block_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:block]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with target account' do
|
|
|
|
target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
|
|
|
|
block = Fabricate(:block, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = block_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
expect(object.id.text).to eq 'https://domain/id'
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers block when processed' do
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
|
|
|
|
xml = OStatus::AtomSerializer.render(block_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair)
|
|
|
|
block.destroy!
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
ProcessInteractionService.new.call(envelope, block.target_account)
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(block.account.blocking?(block.target_account)).to be true
|
|
|
|
end
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
describe '#unblock_salmon' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns entry element' do
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(unblock_salmon.name).to eq 'entry'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
block = Fabricate(:block)
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(unblock_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
|
|
|
|
.or(eq(TagManager.instance.unique_tag(time_after.utc, block.id, 'Block')))
|
|
|
|
)
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
block = Fabricate(:block, account: account, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unblock_salmon.title.text).to eq 'account no longer blocks target_account@remote'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
block = Fabricate(:block, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unblock_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/account'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
block = Fabricate(:block)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = unblock_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:verb element with block' do
|
|
|
|
block = Fabricate(:block)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = unblock_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:unblock]
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:object element with target account' do
|
|
|
|
target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
|
|
|
|
block = Fabricate(:block, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = unblock_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
expect(object.id.text).to eq 'https://domain/id'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers block when processed' do
|
|
|
|
block = Fabricate(:block)
|
2017-07-18 23:37:26 +00:00
|
|
|
unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
|
|
|
|
xml = OStatus::AtomSerializer.render(unblock_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, block.account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, block.target_account)
|
|
|
|
|
|
|
|
expect{ block.reload }.to raise_error ActiveRecord::RecordNotFound
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#favourite_salmon' do
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(favourite_salmon.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
favourite = Fabricate(:favourite, created_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(favourite_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{favourite.id}:objectType=Favourite"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
favourite = Fabricate(:favourite, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(favourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
favourite = Fabricate(:favourite)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = favourite_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity'
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends activity:verb element with favorite' do
|
|
|
|
favourite = Fabricate(:favourite)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = favourite_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:favorite]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with status' do
|
|
|
|
status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
favourite = Fabricate(:favourite, status: status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = favourite_salmon.nodes.find { |node| node.name == 'activity:object' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(object.id.text).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends thr:in-reply-to element for status' do
|
|
|
|
status_account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
favourite = Fabricate(:favourite, status: status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
in_reply_to = favourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(in_reply_to.ref).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(in_reply_to.href).to eq "https://cb6e6126.ngrok.io/@username/#{status.id}"
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'includes description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
status_account = Fabricate(:account, domain: 'remote', username: 'status_account')
|
|
|
|
status = Fabricate(:status, account: status_account)
|
|
|
|
favourite = Fabricate(:favourite, account: account, status: status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(favourite_salmon.title.text).to eq 'account favourited a status by status_account@remote'
|
|
|
|
expect(favourite_salmon.content.text).to eq 'account favourited a status by status_account@remote'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers favourite when processed' do
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
favourite_salmon = OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
|
|
|
xml = OStatus::AtomSerializer.render(favourite_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair)
|
|
|
|
favourite.destroy!
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, favourite.status.account)
|
|
|
|
expect(favourite.account.favourited?(favourite.status)).to be true
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unfavourite_salmon' do
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.favourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(unfavourite_salmon.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
favourite = Fabricate(:favourite)
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(unfavourite_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, favourite.id, 'Favourite'))
|
|
|
|
.or(eq(TagManager.instance.unique_tag(time_after.utc, favourite.id, 'Favourite')))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
favourite = Fabricate(:favourite, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfavourite_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
favourite = Fabricate(:favourite)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq 'http://activitystrea.ms/schema/1.0/activity'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with favorite' do
|
|
|
|
favourite = Fabricate(:favourite)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = unfavourite_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:unfavorite]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with status' do
|
|
|
|
status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
favourite = Fabricate(:favourite, status: status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = unfavourite_salmon.nodes.find { |node| node.name == 'activity:object' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(object.id.text).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends thr:in-reply-to element for status' do
|
|
|
|
status_account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: status_account, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
favourite = Fabricate(:favourite, status: status)
|
2017-04-18 20:30:17 +00:00
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
in_reply_to = unfavourite_salmon.nodes.find { |node| node.name == 'thr:in-reply-to' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(in_reply_to.ref).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(in_reply_to.href).to eq "https://cb6e6126.ngrok.io/@username/#{status.id}"
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'includes description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
status_account = Fabricate(:account, domain: 'remote', username: 'status_account')
|
|
|
|
status = Fabricate(:status, account: status_account)
|
|
|
|
favourite = Fabricate(:favourite, account: account, status: status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfavourite_salmon.title.text).to eq 'account no longer favourites a status by status_account@remote'
|
|
|
|
expect(unfavourite_salmon.content.text).to eq 'account no longer favourites a status by status_account@remote'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers unfavourite when processed' do
|
|
|
|
favourite = Fabricate(:favourite)
|
2017-07-18 23:37:26 +00:00
|
|
|
unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
|
|
|
|
xml = OStatus::AtomSerializer.render(unfavourite_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, favourite.account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, favourite.status.account)
|
|
|
|
expect { favourite.reload }.to raise_error ActiveRecord::RecordNotFound
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
describe '#follow_salmon' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
follow = Fabricate(:follow)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
follow = Fabricate(:follow)
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(follow_salmon.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
follow = Fabricate(:follow, created_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(follow_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{follow.id}:objectType=Follow"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
follow = Fabricate(:follow, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(follow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = follow_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with follow' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = follow_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:follow]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with target account' do
|
|
|
|
target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
|
|
|
|
follow = Fabricate(:follow, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = follow_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
expect(object.id.text).to eq 'https://domain/id'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'includes description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
follow = Fabricate(:follow, account: account, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(follow_salmon.title.text).to eq 'account started following target_account@remote'
|
|
|
|
expect(follow_salmon.content.text).to eq 'account started following target_account@remote'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers follow when processed' do
|
|
|
|
follow = Fabricate(:follow)
|
2017-07-18 23:37:26 +00:00
|
|
|
follow_salmon = OStatus::AtomSerializer.new.follow_salmon(follow)
|
|
|
|
xml = OStatus::AtomSerializer.render(follow_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
follow.destroy!
|
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, follow.target_account)
|
|
|
|
|
|
|
|
expect(follow.account.following?(follow.target_account)).to be true
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
describe '#unfollow_salmon' do
|
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns entry element' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfollow_salmon.name).to eq 'entry'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(unfollow_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, follow.id, 'Follow'))
|
|
|
|
.or(eq(TagManager.instance.unique_tag(time_after.utc, follow.id, 'Follow')))
|
|
|
|
)
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
follow = Fabricate(:follow, account: account, target_account: target_account)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfollow_salmon.title.text).to eq 'account is no longer following target_account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends content element with description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
follow = Fabricate(:follow, account: account, target_account: target_account)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfollow_salmon.content.text).to eq 'account is no longer following target_account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'username')
|
|
|
|
follow = Fabricate(:follow, account: account)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(unfollow_salmon.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = unfollow_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with follow' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = unfollow_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:unfollow]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object element with target account' do
|
|
|
|
target_account = Fabricate(:account, domain: 'domain', uri: 'https://domain/id')
|
|
|
|
follow = Fabricate(:follow, target_account: target_account)
|
|
|
|
follow.destroy!
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object = unfollow_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
expect(object.id.text).to eq 'https://domain/id'
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
2017-06-03 18:51:08 +00:00
|
|
|
it 'returns element whose rendered view triggers unfollow when processed' do
|
|
|
|
follow = Fabricate(:follow)
|
|
|
|
follow.destroy!
|
2017-07-18 23:37:26 +00:00
|
|
|
unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
|
|
|
|
xml = OStatus::AtomSerializer.render(unfollow_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
follow.account.follow!(follow.target_account)
|
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, follow.account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, follow.target_account)
|
|
|
|
|
|
|
|
expect(follow.account.following?(follow.target_account)).to be false
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#follow_request_salmon' do
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context do
|
|
|
|
def serialize(follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'follow request salmon'
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
follow_request = Fabricate(:follow_request, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
expect(follow_request_salmon.id.text).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{follow_request.id}:objectType=FollowRequest"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: nil, username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: 'remote', username: 'target_account')
|
|
|
|
follow_request = Fabricate(:follow_request, account: account, target_account: target_account)
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
|
|
|
expect(follow_request_salmon.title.text).to eq 'account requested to follow target_account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns element whose rendered view triggers follow request when processed' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
follow_request_salmon = serialize(follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
xml = OStatus::AtomSerializer.render(follow_request_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, follow_request.account.keypair)
|
|
|
|
follow_request.destroy!
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, follow_request.target_account)
|
|
|
|
|
|
|
|
expect(follow_request.account.requested?(follow_request.target_account)).to eq true
|
|
|
|
end
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#authorize_follow_request_salmon' do
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'follow request salmon' do
|
|
|
|
def serialize(follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(authorize_follow_request_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
|
|
|
|
.or(eq(TagManager.instance.unique_tag(time_after.utc, follow_request.id, 'FollowRequest')))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: 'remote', username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: nil, username: 'target_account')
|
|
|
|
follow_request = Fabricate(:follow_request, account: account, target_account: target_account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(authorize_follow_request_salmon.title.text).to eq 'target_account authorizes follow request by account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with authorize' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
verb = authorize_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:authorize]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns element whose rendered view creates follow from follow request when processed' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
|
|
|
|
xml = OStatus::AtomSerializer.render(authorize_follow_request_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, follow_request.account)
|
|
|
|
|
|
|
|
expect(follow_request.account.following?(follow_request.target_account)).to eq true
|
|
|
|
expect { follow_request.reload }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#reject_follow_request_salmon' do
|
2017-06-03 18:51:08 +00:00
|
|
|
include_examples 'namespaces' do
|
|
|
|
def serialize
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'follow request salmon' do
|
|
|
|
def serialize(follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with unique tag' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
|
|
|
|
|
|
|
time_before = Time.now
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
time_after = Time.now
|
|
|
|
|
|
|
|
expect(reject_follow_request_salmon.id.text).to(
|
|
|
|
eq(TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
|
|
|
|
.or(TagManager.instance.unique_tag(time_after.utc, follow_request.id, 'FollowRequest'))
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with description' do
|
|
|
|
account = Fabricate(:account, domain: 'remote', username: 'account')
|
|
|
|
target_account = Fabricate(:account, domain: nil, username: 'target_account')
|
|
|
|
follow_request = Fabricate(:follow_request, account: account, target_account: target_account)
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(reject_follow_request_salmon.title.text).to eq 'target_account rejects follow request by account@remote'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with activity type' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
object_type = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:activity]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with authorize' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
2017-06-03 18:51:08 +00:00
|
|
|
verb = reject_follow_request_salmon.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(verb.text).to eq TagManager::VERBS[:reject]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns element whose rendered view deletes follow request when processed' do
|
|
|
|
follow_request = Fabricate(:follow_request)
|
2017-07-18 23:37:26 +00:00
|
|
|
reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
|
|
|
|
xml = OStatus::AtomSerializer.render(reject_follow_request_salmon)
|
2017-06-03 18:51:08 +00:00
|
|
|
envelope = OStatus2::Salmon.new.pack(xml, follow_request.target_account.keypair)
|
|
|
|
|
|
|
|
ProcessInteractionService.new.call(envelope, follow_request.account)
|
|
|
|
|
|
|
|
expect(follow_request.account.following?(follow_request.target_account)).to eq false
|
|
|
|
expect { follow_request.reload }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#object' do
|
|
|
|
include_examples 'status attributes' do
|
|
|
|
def serialize(status)
|
2017-07-18 23:37:26 +00:00
|
|
|
OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns activity:object element' do
|
|
|
|
status = Fabricate(:status)
|
2017-07-18 23:37:26 +00:00
|
|
|
object = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(object.name).to eq 'activity:object'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends id element with URL for status' do
|
|
|
|
status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
object = OStatus::AtomSerializer.new.object(status)
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(object.id.text).to eq "https://cb6e6126.ngrok.io/users/#{status.account.to_param}/statuses/#{status.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends published element with created date' do
|
|
|
|
status = Fabricate(:status, created_at: '2000-01-01T00:00:00Z')
|
2017-07-18 23:37:26 +00:00
|
|
|
object = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(object.published.text).to eq '2000-01-01T00:00:00Z'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends updated element with updated date' do
|
2017-09-06 17:01:28 +00:00
|
|
|
status = Fabricate(:status)
|
|
|
|
status.updated_at = '2000-01-01T00:00:00Z'
|
2017-07-18 23:37:26 +00:00
|
|
|
object = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(object.updated.text).to eq '2000-01-01T00:00:00Z'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends title element with title' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
object = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(object.title.text).to eq 'New status by username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends author element with account' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
expect(entry.author.id.text).to eq 'https://cb6e6126.ngrok.io/users/username'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:object-type element with object type' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = entry.nodes.find { |node| node.name == 'activity:object-type' }
|
|
|
|
expect(object_type.text).to eq TagManager::TYPES[:note]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends activity:verb element with verb' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
object_type = entry.nodes.find { |node| node.name == 'activity:verb' }
|
|
|
|
expect(object_type.text).to eq TagManager::VERBS[:post]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends link element for an alternative' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
status = Fabricate(:status, account: account)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
2017-08-17 23:03:18 +00:00
|
|
|
link = entry.nodes.find { |node| node.name == 'link' && node[:rel] == 'alternate' && node[:type] == 'text/html' }
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(link[:type]).to eq 'text/html'
|
|
|
|
expect(link[:href]).to eq "https://cb6e6126.ngrok.io/@username/#{status.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends thr:in-reply-to element if it is a reply and thread is not nil' do
|
|
|
|
account = Fabricate(:account, username: 'username')
|
|
|
|
thread = Fabricate(:status, account: account, created_at: '2000-01-01T00:00:00Z')
|
|
|
|
reply = Fabricate(:status, thread: thread)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(reply)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
in_reply_to = entry.nodes.find { |node| node.name == 'thr:in-reply-to' }
|
2017-09-06 17:01:28 +00:00
|
|
|
expect(in_reply_to.ref).to eq "https://cb6e6126.ngrok.io/users/#{thread.account.to_param}/statuses/#{thread.id}"
|
2017-06-03 18:51:08 +00:00
|
|
|
expect(in_reply_to.href).to eq "https://cb6e6126.ngrok.io/@username/#{thread.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append thr:in-reply-to element if thread is nil' do
|
|
|
|
status = Fabricate(:status, thread: nil)
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
entry.nodes.each { |node| expect(node.name).not_to eq 'thr:in-reply-to' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not append ostatus:conversation element if conversation_id is nil' do
|
|
|
|
status = Fabricate.build(:status, conversation_id: nil)
|
|
|
|
status.save!(validate: false)
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
entry.nodes.each { |node| expect(node.name).not_to eq 'ostatus:conversation' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends ostatus:conversation element if conversation_id is not nil' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
status.conversation.update!(created_at: '2000-01-01T00:00:00Z')
|
|
|
|
|
2017-07-18 23:37:26 +00:00
|
|
|
entry = OStatus::AtomSerializer.new.object(status)
|
2017-06-03 18:51:08 +00:00
|
|
|
|
|
|
|
conversation = entry.nodes.find { |node| node.name == 'ostatus:conversation' }
|
|
|
|
expect(conversation[:ref]).to eq "tag:cb6e6126.ngrok.io,2000-01-01:objectId=#{status.conversation.id}:objectType=Conversation"
|
|
|
|
end
|
2017-04-18 20:30:17 +00:00
|
|
|
end
|
2017-04-17 23:07:46 +00:00
|
|
|
end
|