The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

94 lines
2.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe ProcessInteractionService do
  3. let(:receiver) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
  4. let(:sender) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  5. subject { ProcessInteractionService.new }
  6. describe 'follow request slap' do
  7. before do
  8. receiver.update(locked: true)
  9. payload = <<XML
  10. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  11. <author>
  12. <name>bob</name>
  13. <uri>https://cb6e6126.ngrok.io/users/bob</uri>
  14. </author>
  15. <id>someIdHere</id>
  16. <activity:verb>http://activitystrea.ms/schema/1.0/request-friend</activity:verb>
  17. </entry>
  18. XML
  19. envelope = OStatus2::Salmon.new.pack(payload, sender.keypair)
  20. subject.call(envelope, receiver)
  21. end
  22. it 'creates a record' do
  23. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to_not be_nil
  24. end
  25. end
  26. describe 'follow request authorization slap' do
  27. before do
  28. receiver.update(locked: true)
  29. FollowRequest.create(account: sender, target_account: receiver)
  30. payload = <<XML
  31. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  32. <author>
  33. <name>alice</name>
  34. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  35. </author>
  36. <id>someIdHere</id>
  37. <activity:verb>http://activitystrea.ms/schema/1.0/authorize</activity:verb>
  38. </entry>
  39. XML
  40. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  41. subject.call(envelope, sender)
  42. end
  43. it 'creates a follow relationship' do
  44. expect(Follow.find_by(account: sender, target_account: receiver)).to_not be_nil
  45. end
  46. it 'removes the follow request' do
  47. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  48. end
  49. end
  50. describe 'follow request rejection slap' do
  51. before do
  52. receiver.update(locked: true)
  53. FollowRequest.create(account: sender, target_account: receiver)
  54. payload = <<XML
  55. <entry xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/">
  56. <author>
  57. <name>alice</name>
  58. <uri>https://cb6e6126.ngrok.io/users/alice</uri>
  59. </author>
  60. <id>someIdHere</id>
  61. <activity:verb>http://activitystrea.ms/schema/1.0/reject</activity:verb>
  62. </entry>
  63. XML
  64. envelope = OStatus2::Salmon.new.pack(payload, receiver.keypair)
  65. subject.call(envelope, sender)
  66. end
  67. it 'does not create a follow relationship' do
  68. expect(Follow.find_by(account: sender, target_account: receiver)).to be_nil
  69. end
  70. it 'removes the follow request' do
  71. expect(FollowRequest.find_by(account: sender, target_account: receiver)).to be_nil
  72. end
  73. end
  74. end