mirror of
https://github.com/whippyshou/mastodon
synced 2024-11-28 06:48:38 +09:00
Speed-up on BackupService
spec (#25527)
This commit is contained in:
parent
6ac271c2a0
commit
0b39b9abee
@ -30,7 +30,7 @@ RSpec.describe BackupService, type: :service do
|
|||||||
it 'stores them as expected' do
|
it 'stores them as expected' do
|
||||||
service_call
|
service_call
|
||||||
|
|
||||||
json = Oj.load(read_zip_file(backup, 'actor.json'))
|
json = export_json(:actor)
|
||||||
avatar_path = json.dig('icon', 'url')
|
avatar_path = json.dig('icon', 'url')
|
||||||
header_path = json.dig('image', 'url')
|
header_path = json.dig('image', 'url')
|
||||||
|
|
||||||
@ -42,47 +42,60 @@ RSpec.describe BackupService, type: :service do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'marks the backup as processed' do
|
it 'marks the backup as processed and exports files' do
|
||||||
expect { service_call }.to change(backup, :processed).from(false).to(true)
|
expect { service_call }.to process_backup
|
||||||
|
|
||||||
|
expect_outbox_export
|
||||||
|
expect_likes_export
|
||||||
|
expect_bookmarks_export
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'exports outbox.json as expected' do
|
def process_backup
|
||||||
service_call
|
change(backup, :processed).from(false).to(true)
|
||||||
|
end
|
||||||
|
|
||||||
json = Oj.load(read_zip_file(backup, 'outbox.json'))
|
def expect_outbox_export
|
||||||
|
json = export_json(:outbox)
|
||||||
|
|
||||||
|
aggregate_failures do
|
||||||
expect(json['@context']).to_not be_nil
|
expect(json['@context']).to_not be_nil
|
||||||
expect(json['type']).to eq 'OrderedCollection'
|
expect(json['type']).to eq 'OrderedCollection'
|
||||||
expect(json['totalItems']).to eq 2
|
expect(json['totalItems']).to eq 2
|
||||||
expect(json['orderedItems'][0]['@context']).to be_nil
|
expect(json['orderedItems'][0]['@context']).to be_nil
|
||||||
expect(json['orderedItems'][0]).to include({
|
expect(json['orderedItems'][0]).to include_create_item(status)
|
||||||
'type' => 'Create',
|
expect(json['orderedItems'][1]).to include_create_item(private_status)
|
||||||
'object' => include({
|
end
|
||||||
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
|
||||||
'content' => '<p>Hello</p>',
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
expect(json['orderedItems'][1]).to include({
|
|
||||||
'type' => 'Create',
|
|
||||||
'object' => include({
|
|
||||||
'id' => ActivityPub::TagManager.instance.uri_for(private_status),
|
|
||||||
'content' => '<p>secret</p>',
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'exports likes.json as expected' do
|
def expect_likes_export
|
||||||
service_call
|
json = export_json(:likes)
|
||||||
|
|
||||||
json = Oj.load(read_zip_file(backup, 'likes.json'))
|
aggregate_failures do
|
||||||
expect(json['type']).to eq 'OrderedCollection'
|
expect(json['type']).to eq 'OrderedCollection'
|
||||||
expect(json['orderedItems']).to eq [ActivityPub::TagManager.instance.uri_for(favourite.status)]
|
expect(json['orderedItems']).to eq [ActivityPub::TagManager.instance.uri_for(favourite.status)]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'exports bookmarks.json as expected' do
|
def expect_bookmarks_export
|
||||||
service_call
|
json = export_json(:bookmarks)
|
||||||
|
|
||||||
json = Oj.load(read_zip_file(backup, 'bookmarks.json'))
|
aggregate_failures do
|
||||||
expect(json['type']).to eq 'OrderedCollection'
|
expect(json['type']).to eq 'OrderedCollection'
|
||||||
expect(json['orderedItems']).to eq [ActivityPub::TagManager.instance.uri_for(bookmark.status)]
|
expect(json['orderedItems']).to eq [ActivityPub::TagManager.instance.uri_for(bookmark.status)]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def export_json(type)
|
||||||
|
Oj.load(read_zip_file(backup, "#{type}.json"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_create_item(status)
|
||||||
|
include({
|
||||||
|
'type' => 'Create',
|
||||||
|
'object' => include({
|
||||||
|
'id' => ActivityPub::TagManager.instance.uri_for(status),
|
||||||
|
'content' => "<p>#{status.text}</p>",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user