This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more migration tests (mastodon#17710)
* Add migration tests for hide_network settings migration * Add tests about suspended/suspended_at * Add more tests regarding the results of migrations * Fix migration test regarding stale conflicting remote account * Add migration tests about AccountConversation
- Loading branch information
1 parent
dba4be1
commit 61ae6b3
Showing
2 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,50 @@ | |
|
||
namespace :tests do | ||
namespace :migrations do | ||
desc 'Check that database state is consistent with a successful migration from populated data' | ||
task check_database: :environment do | ||
unless Account.find_by(username: 'admin', domain: nil)&.hide_collections? == false | ||
puts 'Unexpected value for Account#hide_collections? for user @admin' | ||
exit(1) | ||
end | ||
|
||
unless Account.find_by(username: 'user', domain: nil)&.hide_collections? == true | ||
puts 'Unexpected value for Account#hide_collections? for user @user' | ||
exit(1) | ||
end | ||
|
||
unless Account.find_by(username: 'evil', domain: 'activitypub.com')&.suspended? | ||
puts 'Unexpected value for Account#suspended? for user @[email protected]' | ||
exit(1) | ||
end | ||
|
||
unless Status.find(6).account_id == Status.find(7).account_id | ||
puts 'Users @[email protected] and @[email protected] not properly merged' | ||
exit(1) | ||
end | ||
|
||
if Account.where(domain: Rails.configuration.x.local_domain).exists? | ||
puts 'Faux remote accounts not properly claned up' | ||
exit(1) | ||
end | ||
|
||
unless AccountConversation.first&.last_status_id == 11 | ||
puts 'AccountConversation records not created as expected' | ||
exit(1) | ||
end | ||
end | ||
|
||
desc 'Populate the database with test data for 2.4.0' | ||
task populate_v2_4: :environment do | ||
ActiveRecord::Base.connection.execute(<<~SQL) | ||
INSERT INTO "settings" | ||
(id, thing_type, thing_id, var, value, created_at, updated_at) | ||
VALUES | ||
(1, 'User', 1, 'hide_network', E'--- false\n', now(), now()), | ||
(2, 'User', 2, 'hide_network', E'--- true\n', now(), now()); | ||
SQL | ||
end | ||
|
||
desc 'Populate the database with test data for 2.0.0' | ||
task populate_v2: :environment do | ||
admin_key = OpenSSL::PKey::RSA.new(2048) | ||
|
@@ -34,7 +78,7 @@ namespace :tests do | |
'https://remote.com/@remote', 'https://remote.com/salmon/1'), | ||
(4, 'Remote', 'remote.com', NULL, #{remote_public_key}, now(), now(), | ||
'https://remote.com/@Remote', 'https://remote.com/salmon/1'), | ||
(5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now(), now(), | ||
(5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now() - interval '1 year', now() - interval '1 year', | ||
'https://remote.com/stale/@REMOTE', 'https://remote.com/stale/salmon/1'); | ||
INSERT INTO "accounts" | ||
|
@@ -49,6 +93,13 @@ namespace :tests do | |
(7, 'user', #{local_domain}, #{user_private_key}, #{user_public_key}, now(), now()), | ||
(8, 'pt_user', NULL, #{user_private_key}, #{user_public_key}, now(), now()); | ||
INSERT INTO "accounts" | ||
(id, username, domain, private_key, public_key, created_at, updated_at, protocol, inbox_url, outbox_url, followers_url, suspended) | ||
VALUES | ||
(9, 'evil', 'activitypub.com', NULL, #{remote_public_key_ap}, now(), now(), | ||
1, 'https://activitypub.com/users/evil/inbox', 'https://activitypub.com/users/evil/outbox', | ||
'https://activitypub.com/users/evil/followers', true); | ||
-- users | ||
INSERT INTO "users" | ||
|
@@ -62,6 +113,9 @@ namespace :tests do | |
VALUES | ||
(3, 7, 'ptuser@localhost', now(), now(), false, 'pt'); | ||
-- conversations | ||
INSERT INTO "conversations" (id, created_at, updated_at) VALUES (1, now(), now()); | ||
-- statuses | ||
INSERT INTO "statuses" | ||
|
@@ -97,14 +151,22 @@ namespace :tests do | |
VALUES | ||
(9, 1, 2, now(), now()); | ||
INSERT INTO "statuses" | ||
(id, account_id, text, in_reply_to_id, conversation_id, visibility, created_at, updated_at) | ||
VALUES | ||
(10, 2, '@admin hey!', NULL, 1, 3, now(), now()), | ||
(11, 1, '@user hey!', 10, 1, 3, now(), now()); | ||
-- mentions (from previous statuses) | ||
INSERT INTO "mentions" | ||
(status_id, account_id, created_at, updated_at) | ||
(id, status_id, account_id, created_at, updated_at) | ||
VALUES | ||
(2, 3, now(), now()), | ||
(3, 4, now(), now()), | ||
(4, 5, now(), now()); | ||
(1, 2, 3, now(), now()), | ||
(2, 3, 4, now(), now()), | ||
(3, 4, 5, now(), now()), | ||
(4, 10, 1, now(), now()), | ||
(5, 11, 2, now(), now()); | ||
-- stream entries | ||
|
@@ -121,7 +183,6 @@ namespace :tests do | |
(8, 5, 'status', now(), now()), | ||
(9, 1, 'status', now(), now()); | ||
-- custom emoji | ||
INSERT INTO "custom_emojis" | ||
|
@@ -161,12 +222,12 @@ namespace :tests do | |
-- follows | ||
INSERT INTO "follows" | ||
(account_id, target_account_id, created_at, updated_at) | ||
(id, account_id, target_account_id, created_at, updated_at) | ||
VALUES | ||
(1, 5, now(), now()), | ||
(6, 2, now(), now()), | ||
(5, 2, now(), now()), | ||
(6, 1, now(), now()); | ||
(1, 1, 5, now(), now()), | ||
(2, 6, 2, now(), now()), | ||
(3, 5, 2, now(), now()), | ||
(4, 6, 1, now(), now()); | ||
-- follow requests | ||
|
@@ -175,6 +236,15 @@ namespace :tests do | |
VALUES | ||
(2, 5, now(), now()), | ||
(5, 1, now(), now()); | ||
-- notifications | ||
INSERT INTO "notifications" | ||
(id, from_account_id, account_id, activity_type, activity_id, created_at, updated_at) | ||
VALUES | ||
(1, 6, 2, 'Follow', 2, now(), now()), | ||
(2, 2, 1, 'Mention', 4, now(), now()), | ||
(3, 1, 2, 'Mention', 5, now(), now()); | ||
SQL | ||
end | ||
end | ||
|