tests.rake 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # frozen_string_literal: true
  2. namespace :tests do
  3. namespace :migrations do
  4. desc 'Populate the database with test data for 2.0.0'
  5. task populate_v2: :environment do
  6. admin_key = OpenSSL::PKey::RSA.new(2048)
  7. user_key = OpenSSL::PKey::RSA.new(2048)
  8. remote_key = OpenSSL::PKey::RSA.new(2048)
  9. remote_key2 = OpenSSL::PKey::RSA.new(2048)
  10. remote_key3 = OpenSSL::PKey::RSA.new(2048)
  11. admin_private_key = ActiveRecord::Base.connection.quote(admin_key.to_pem)
  12. admin_public_key = ActiveRecord::Base.connection.quote(admin_key.public_key.to_pem)
  13. user_private_key = ActiveRecord::Base.connection.quote(user_key.to_pem)
  14. user_public_key = ActiveRecord::Base.connection.quote(user_key.public_key.to_pem)
  15. remote_public_key = ActiveRecord::Base.connection.quote(remote_key.public_key.to_pem)
  16. remote_public_key2 = ActiveRecord::Base.connection.quote(remote_key2.public_key.to_pem)
  17. remote_public_key_ap = ActiveRecord::Base.connection.quote(remote_key3.public_key.to_pem)
  18. local_domain = ActiveRecord::Base.connection.quote(Rails.configuration.x.local_domain)
  19. ActiveRecord::Base.connection.execute(<<~SQL)
  20. -- accounts
  21. INSERT INTO "accounts"
  22. (id, username, domain, private_key, public_key, created_at, updated_at)
  23. VALUES
  24. (1, 'admin', NULL, #{admin_private_key}, #{admin_public_key}, now(), now()),
  25. (2, 'user', NULL, #{user_private_key}, #{user_public_key}, now(), now());
  26. INSERT INTO "accounts"
  27. (id, username, domain, private_key, public_key, created_at, updated_at, remote_url, salmon_url)
  28. VALUES
  29. (3, 'remote', 'remote.com', NULL, #{remote_public_key}, now(), now(),
  30. 'https://remote.com/@remote', 'https://remote.com/salmon/1'),
  31. (4, 'Remote', 'remote.com', NULL, #{remote_public_key}, now(), now(),
  32. 'https://remote.com/@Remote', 'https://remote.com/salmon/1'),
  33. (5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now(), now(),
  34. 'https://remote.com/stale/@REMOTE', 'https://remote.com/stale/salmon/1');
  35. INSERT INTO "accounts"
  36. (id, username, domain, private_key, public_key, created_at, updated_at, protocol, inbox_url, outbox_url, followers_url)
  37. VALUES
  38. (6, 'bob', 'activitypub.com', NULL, #{remote_public_key_ap}, now(), now(),
  39. 1, 'https://activitypub.com/users/bob/inbox', 'https://activitypub.com/users/bob/outbox', 'https://activitypub.com/users/bob/followers');
  40. INSERT INTO "accounts"
  41. (id, username, domain, private_key, public_key, created_at, updated_at)
  42. VALUES
  43. (7, 'user', #{local_domain}, #{user_private_key}, #{user_public_key}, now(), now()),
  44. (8, 'pt_user', NULL, #{user_private_key}, #{user_public_key}, now(), now());
  45. -- users
  46. INSERT INTO "users"
  47. (id, account_id, email, created_at, updated_at, admin)
  48. VALUES
  49. (1, 1, 'admin@localhost', now(), now(), true),
  50. (2, 2, 'user@localhost', now(), now(), false);
  51. INSERT INTO "users"
  52. (id, account_id, email, created_at, updated_at, admin, locale)
  53. VALUES
  54. (3, 7, 'ptuser@localhost', now(), now(), false, 'pt');
  55. -- statuses
  56. INSERT INTO "statuses"
  57. (id, account_id, text, created_at, updated_at)
  58. VALUES
  59. (1, 1, 'test', now(), now()),
  60. (2, 1, '@remote@remote.com hello', now(), now()),
  61. (3, 1, '@Remote@remote.com hello', now(), now()),
  62. (4, 1, '@REMOTE@remote.com hello', now(), now());
  63. INSERT INTO "statuses"
  64. (id, account_id, text, created_at, updated_at, uri, local)
  65. VALUES
  66. (5, 1, 'activitypub status', now(), now(), 'https://localhost/users/admin/statuses/4', true);
  67. INSERT INTO "statuses"
  68. (id, account_id, text, created_at, updated_at)
  69. VALUES
  70. (6, 3, 'test', now(), now());
  71. INSERT INTO "statuses"
  72. (id, account_id, text, created_at, updated_at, in_reply_to_id, in_reply_to_account_id)
  73. VALUES
  74. (7, 4, '@admin hello', now(), now(), 3, 1);
  75. INSERT INTO "statuses"
  76. (id, account_id, text, created_at, updated_at)
  77. VALUES
  78. (8, 5, 'test', now(), now());
  79. INSERT INTO "statuses"
  80. (id, account_id, reblog_of_id, created_at, updated_at)
  81. VALUES
  82. (9, 1, 2, now(), now());
  83. -- mentions (from previous statuses)
  84. INSERT INTO "mentions"
  85. (status_id, account_id, created_at, updated_at)
  86. VALUES
  87. (2, 3, now(), now()),
  88. (3, 4, now(), now()),
  89. (4, 5, now(), now());
  90. -- stream entries
  91. INSERT INTO "stream_entries"
  92. (activity_id, account_id, activity_type, created_at, updated_at)
  93. VALUES
  94. (1, 1, 'status', now(), now()),
  95. (2, 1, 'status', now(), now()),
  96. (3, 1, 'status', now(), now()),
  97. (4, 1, 'status', now(), now()),
  98. (5, 1, 'status', now(), now()),
  99. (6, 3, 'status', now(), now()),
  100. (7, 4, 'status', now(), now()),
  101. (8, 5, 'status', now(), now()),
  102. (9, 1, 'status', now(), now());
  103. -- custom emoji
  104. INSERT INTO "custom_emojis"
  105. (shortcode, created_at, updated_at)
  106. VALUES
  107. ('test', now(), now()),
  108. ('Test', now(), now()),
  109. ('blobcat', now(), now());
  110. INSERT INTO "custom_emojis"
  111. (shortcode, domain, uri, created_at, updated_at)
  112. VALUES
  113. ('blobcat', 'remote.org', 'https://remote.org/emoji/blobcat', now(), now()),
  114. ('blobcat', 'Remote.org', 'https://remote.org/emoji/blobcat', now(), now()),
  115. ('Blobcat', 'remote.org', 'https://remote.org/emoji/Blobcat', now(), now());
  116. -- favourites
  117. INSERT INTO "favourites"
  118. (account_id, status_id, created_at, updated_at)
  119. VALUES
  120. (1, 1, now(), now()),
  121. (1, 7, now(), now()),
  122. (4, 1, now(), now()),
  123. (3, 1, now(), now()),
  124. (5, 1, now(), now());
  125. -- pinned statuses
  126. INSERT INTO "status_pins"
  127. (account_id, status_id, created_at, updated_at)
  128. VALUES
  129. (1, 1, now(), now()),
  130. (3, 6, now(), now()),
  131. (4, 7, now(), now());
  132. -- follows
  133. INSERT INTO "follows"
  134. (account_id, target_account_id, created_at, updated_at)
  135. VALUES
  136. (1, 5, now(), now()),
  137. (6, 2, now(), now()),
  138. (5, 2, now(), now()),
  139. (6, 1, now(), now());
  140. -- follow requests
  141. INSERT INTO "follow_requests"
  142. (account_id, target_account_id, created_at, updated_at)
  143. VALUES
  144. (2, 5, now(), now()),
  145. (5, 1, now(), now());
  146. SQL
  147. end
  148. end
  149. end