Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing/attendes #29

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions spec/requests/api/v1/attendee_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
it "creates a new attendee" do
user_id = @user2.id
event_id = @event1.id
host = false
# host = false

post "/api/v1/attendees", params: { attendee: { user_id: user_id, event_id: event_id } }
# require 'pry'; binding.pry
# require 'pry'; binding.pry
attendee = JSON.parse(response.body, symbolize_names: true)

expect(response).to be_successful
Expand All @@ -49,6 +49,27 @@

end

it 'cant create attendee' do
user_id = User.create(name: 'John Doe', email: '')
event_id = @event1.id
# host = false

post "/api/v1/attendees", params: { attendee: { user_id: user_id, event_id: event_id } }
# require 'pry'; binding.pry

expect(response).to_not be_successful
expect(response.status).to eq(422)
attendee = JSON.parse(response.body, symbolize_names: true)

expect(attendee).to be_a(Hash)
# require 'pry'; binding.pry
expect(attendee).to have_key(:errors)

expect(attendee[:errors]).to be_a(Array)
expect(attendee[:errors].first).to be_a(String)
expect(attendee[:errors].first).to eq("User must exist")
end

# it "updates an existing attendee" do
# atttendee_id = @attendee.id
# new_user_id = @user2.id
Expand Down Expand Up @@ -79,4 +100,57 @@

expect(Attendee.find_by(id: attendee_id)).to be_nil
end

it 'cant destory a attendee there is no attendee there' do
attendee_id = '12345678765432345676543456754'

delete "/api/v1/attendees/#{attendee_id}"


expect(response).to_not be_successful
expect(response.status).to eq(404)
# require 'pry'; binding.pry
attendee = JSON.parse(response.body, symbolize_names: true)

expect(attendee).to have_key(:errors)
expect(attendee[:errors]).to be_a(String)
expect(attendee[:errors]).to eq("Attendee not found")
end


describe 'index' do

it 'returns attendees' do
get "/api/v1/attendees?event_id=#{@event1.id}"

expect(response).to be_successful
expect(response.status).to eq(200)

attendees = JSON.parse(response.body, symbolize_names: true)
# require 'pry'; binding.pry
expect(attendees).to have_key(:data)
expect(attendees).to be_a(Hash)
expect(attendees.count).to eq(1)
expect(attendees).to have_key(:data)

expect(attendees[:data]).to be_a(Array)
expect(attendees[:data].first).to have_key(:id)
expect(attendees[:data].first[:id]).to be_a(String)
expect(attendees[:data].first[:id]).to eq("#{attendees[:data].first[:id]}")

expect(attendees[:data].first).to have_key(:type)
expect(attendees[:data].first[:type]).to be_a(String)
expect(attendees[:data].first[:type]).to eq("attendee")

expect(attendees[:data].first).to have_key(:attributes)
expect(attendees[:data].first[:attributes]).to be_a(Hash)

# require 'pry'; binding.pry
expect(attendees[:data].first[:attributes][:user_id]).to be_a(Integer)
expect(attendees[:data].first[:attributes][:user_id]).to eq(attendees[:data].first[:attributes][:user_id])

expect(attendees[:data].first[:attributes][:event_id]).to be_a(Integer)
expect(attendees[:data].first[:attributes][:event_id]).to eq(attendees[:data].first[:attributes][:event_id])
end
end
end