This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
torresed
committed
Feb 18, 2021
1 parent
a257ee5
commit 751971f
Showing
4 changed files
with
167 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe PartiesController, type: :request do | ||
context 'when logged out' do | ||
let(:friend) { create(:user) } | ||
|
||
describe 'GET #show' do | ||
it 'renders an unauthorized response' do | ||
get parties_url, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
describe 'POST #create' do | ||
it 'renders an unauthorized response' do | ||
post parties_url, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
describe 'POST #kick' do | ||
it 'renders an unauthorized response' do | ||
post parties_kick_url, params: { id: friend.id.to_s }, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
describe 'PATCH #update' do | ||
it 'renders an unauthorized response' do | ||
patch parties_url, params: { id: friend.id.to_s }, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
describe 'PUT #update' do | ||
it 'renders an unauthorized response' do | ||
put parties_url, params: { id: friend.id.to_s }, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
it 'renders an unauthorized response' do | ||
delete parties_url, params: { id: friend.id.to_s }, as: :json | ||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
end | ||
|
||
context 'when logged in' do | ||
let(:user) { create(:user) } | ||
let(:friend) { create(:user) } | ||
|
||
let(:valid_headers) do | ||
{ authorization: "Token #{user.auth_token}" } | ||
end | ||
|
||
let(:valid_headers_friend) do | ||
{ authorization: "Token #{friend.auth_token}" } | ||
end | ||
|
||
describe 'GET #show' do | ||
it 'gets party' do | ||
get parties_url, headers: valid_headers, as: :json | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
describe 'POST #create' do | ||
it 'sends a party invitation' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed) | ||
post parties_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Friend has been invited.')) | ||
expect(user.invitations_pending).to include(friend) | ||
end | ||
end | ||
|
||
it 'fails to send a self invitation' do | ||
post parties_url, params: { id: user.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Friend could not be invited.')) | ||
expect(user.invitations_pending).not_to include(user) | ||
end | ||
|
||
it 'fails to send an invite if there is one already pending' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :invited) | ||
post parties_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Friend could not be invited.')) | ||
end | ||
|
||
describe 'PUT #update' do | ||
it 'accepts a party invitation' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :invited) | ||
put parties_url, params: { id: user.id.to_s }, headers: valid_headers_friend, as: :json | ||
expect(response.body).to match(a_string_including('Invitation accepted.')) | ||
expect(user.party_members).to include(friend) | ||
end | ||
|
||
it 'fails to accept a nonexistent invitation' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :unsolicited) | ||
put parties_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Invitation could not be accepted.')) | ||
expect(user.party_members).not_to include(friend) | ||
end | ||
end | ||
|
||
describe 'DELETE #destroy' do | ||
it 'disbands a party' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :accepted) | ||
delete parties_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Party has been disbanded.')) | ||
expect(user.friends_pending).not_to include(friend) | ||
end | ||
end | ||
|
||
describe 'POST #kick' do | ||
it 'kicks a party member' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :accepted) | ||
post parties_kick_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Friend has been kicked.')) | ||
expect(user.party_members).not_to include(friend) | ||
end | ||
|
||
it 'fails to kick a friend that is not in party' do | ||
Friends.create(sent_by: user, sent_to: friend, status: :confirmed, invitation: :invited) | ||
post parties_kick_url, params: { id: friend.id.to_s }, headers: valid_headers, as: :json | ||
expect(response.body).to match(a_string_including('Friend could not be kicked.')) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe PartiesController, type: :routing do | ||
describe 'routing' do | ||
it 'routes to #show via GET' do | ||
expect(get: '/parties').to route_to('parties#show') | ||
end | ||
|
||
it 'routes to #create via POST' do | ||
expect(post: '/parties').to route_to('parties#create') | ||
end | ||
|
||
it 'routes to #kick via POST' do | ||
expect(post: '/parties/kick').to route_to('parties#kick') | ||
end | ||
|
||
it 'routes to #update via PUT' do | ||
expect(put: '/parties').to route_to('parties#update') | ||
end | ||
|
||
it 'routes to #update via PATCH' do | ||
expect(patch: '/parties').to route_to('parties#update') | ||
end | ||
|
||
it 'routes to #destroy via DELETE' do | ||
expect(delete: '/parties').to route_to('parties#destroy') | ||
end | ||
end | ||
end |