Writing out more tests, fixed some bugs
This commit is contained in:
parent
e14b76c7cb
commit
b640f35621
23 changed files with 1069 additions and 41 deletions
|
@ -1,27 +1,71 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::AccountsController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { double acceptable?: true, resource_owner_id: user.id }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success'
|
||||
it 'returns http success' do
|
||||
get :show, id: user.account.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #statuses' do
|
||||
it 'returns http success'
|
||||
it 'returns http success' do
|
||||
get :statuses, id: user.account.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #followers' do
|
||||
it 'returns http success'
|
||||
it 'returns http success' do
|
||||
get :followers, id: user.account.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #following' do
|
||||
it 'returns http success'
|
||||
it 'returns http success' do
|
||||
get :following, id: user.account.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #follow' do
|
||||
it 'returns http success'
|
||||
let(:other_account) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
post :follow, id: other_account.id
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates a following relation between user and target user' do
|
||||
expect(user.account.following?(other_account)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #unfollow' do
|
||||
it 'returns http success'
|
||||
let(:other_account) { Fabricate(:account, username: 'bob') }
|
||||
|
||||
before do
|
||||
user.account.follow!(other_account)
|
||||
post :unfollow, id: other_account.id
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'removes the following relation between user and target user' do
|
||||
expect(user.account.following?(other_account)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,48 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::FollowsController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { double acceptable?: true, resource_owner_id: user.id }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'returns http success'
|
||||
before do
|
||||
stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
|
||||
stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
|
||||
stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
|
||||
stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
|
||||
stub_request(:post, "https://quitter.no/main/push/hub").to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:post, "https://quitter.no/main/salmon/user/7477").to_return(:status => 200, :body => "", :headers => {})
|
||||
stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
|
||||
|
||||
post :create, uri: 'gargron@quitter.no'
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates account for remote user' do
|
||||
expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
|
||||
end
|
||||
|
||||
it 'creates a follow relation between user and remote user' do
|
||||
expect(user.account.following?(Account.find_by(username: 'gargron', domain: 'quitter.no'))).to be true
|
||||
end
|
||||
|
||||
it 'sends a salmon slap to the remote user' do
|
||||
expect(a_request(:post, "https://quitter.no/main/salmon/user/7477")).to have_been_made
|
||||
end
|
||||
|
||||
it 'notifies own hub' do
|
||||
expect(a_request(:post, "https://pubsubhubbub.superfeedr.com/")).to have_been_made
|
||||
end
|
||||
|
||||
it 'subscribes to remote hub' do
|
||||
expect(a_request(:post, "https://quitter.no/main/push/hub")).to have_been_made
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,35 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::SalmonController, type: :controller do
|
||||
let(:account) { Fabricate(:account, username: 'catsrgr8', user: Fabricate(:user)) }
|
||||
|
||||
before do
|
||||
stub_request(:get, "https://quitter.no/.well-known/host-meta").to_return(request_fixture('.host-meta.txt'))
|
||||
stub_request(:get, "https://quitter.no/.well-known/webfinger?resource=acct:gargron@quitter.no").to_return(request_fixture('webfinger.txt'))
|
||||
stub_request(:get, "https://quitter.no/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt'))
|
||||
stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
|
||||
end
|
||||
|
||||
describe 'POST #update' do
|
||||
pending
|
||||
before do
|
||||
request.env['RAW_POST_DATA'] = File.read(File.join(Rails.root, 'spec', 'fixtures', 'salmon', 'mention.xml'))
|
||||
post :update, id: account.id
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'creates remote account' do
|
||||
expect(Account.find_by(username: 'gargron', domain: 'quitter.no')).to_not be_nil
|
||||
end
|
||||
|
||||
it 'creates status' do
|
||||
expect(Status.find_by(uri: 'tag:quitter.no,2016-03-20:noticeId=1276923:objectType=note')).to_not be_nil
|
||||
end
|
||||
|
||||
it 'creates mention for target account' do
|
||||
expect(account.mentions.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::StatusesController, type: :controller do
|
||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
||||
let(:token) { double acceptable?: true, resource_owner_id: user.id }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http success'
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, id: status.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #home' do
|
||||
|
|
|
@ -1,11 +1,40 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::SubscriptionsController, type: :controller do
|
||||
let(:account) { Fabricate(:account, username: 'gargron', domain: 'quitter.no', verify_token: '123', remote_url: 'topic_url', secret: 'abc') }
|
||||
|
||||
describe 'GET #show' do
|
||||
pending
|
||||
before do
|
||||
get :show, id: account.id, 'hub.topic': 'topic_url', 'hub.verify_token': 123, 'hub.challenge': '456'
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'echoes back the challenge' do
|
||||
expect(response.body).to match '456'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #update' do
|
||||
pending
|
||||
let(:feed) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
|
||||
|
||||
before do
|
||||
stub_request(:get, "https://quitter.no/avatar/7477-300-20160211190340.png").to_return(request_fixture('avatar.txt'))
|
||||
|
||||
request.env['HTTP_X_HUB_SIGNATURE'] = "sha1=#{OpenSSL::HMAC.hexdigest('sha1', 'abc', feed)}"
|
||||
request.env['RAW_POST_DATA'] = feed
|
||||
|
||||
post :update, id: account.id
|
||||
end
|
||||
|
||||
it 'returns http created' do
|
||||
expect(response).to have_http_status(:created)
|
||||
end
|
||||
|
||||
it 'creates statuses for feed' do
|
||||
expect(account.statuses.count).to_not eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue