All checks were successful
Ruby on Rails Test / rails-test (push) Successful in 1m7s
- Added dedicated CartsController for session-based cart storage - Refactored routes to use POST /api/v1/carts/store - Updated ticket selection JS to use dynamic data attributes for URLs - Fixed CSRF protection in API and checkout payment increment - Made checkout button URLs dynamic via data attributes - Updated tests for new cart storage endpoint - Removed obsolete store_cart from EventsController
59 lines
2.2 KiB
Ruby
59 lines
2.2 KiB
Ruby
require "test_helper"
|
|
|
|
class Api::V1::EventsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
ENV["API_KEY"] = "test_key"
|
|
@user = User.create!(email: "test@example.com", password: "password123", password_confirmation: "password123")
|
|
@event = Event.create!(name: "Test Event", slug: "test-event", description: "A description that is long enough for validation", latitude: 48.8566, longitude: 2.3522, venue_name: "Venue", venue_address: "Address", user: @user, start_time: 1.week.from_now, end_time: 1.week.from_now + 3.hours, state: :published)
|
|
end
|
|
|
|
test "should get index" do
|
|
get api_v1_events_url, headers: headers_api_key
|
|
assert_response :success
|
|
assert_kind_of Array, json_response
|
|
end
|
|
|
|
test "should show event" do
|
|
get api_v1_event_url(@event.id), headers: headers_api_key
|
|
assert_response :success
|
|
assert_equal @event.id, json_response["id"]
|
|
end
|
|
|
|
test "should create event" do
|
|
assert_difference("Event.count") do
|
|
post api_v1_events_url, params: { event: { name: "New Event", slug: "new-event", description: "New description that is long enough", latitude: 48.8566, longitude: 2.3522, venue_name: "New Venue", venue_address: "New Address", user_id: @user.id, start_time: "2024-01-01 10:00:00", end_time: "2024-01-01 13:00:00", state: "published" } }, as: :json, headers: headers_api_key
|
|
end
|
|
assert_response :created
|
|
end
|
|
|
|
test "should update event" do
|
|
patch api_v1_event_url(@event.id), params: { event: { name: "Updated Event" } }, as: :json, headers: headers_api_key
|
|
assert_response :ok
|
|
@event.reload
|
|
assert_equal "Updated Event", @event.name
|
|
end
|
|
|
|
test "should destroy event" do
|
|
assert_difference("Event.count", -1) do
|
|
delete api_v1_event_url(@event.id), headers: headers_api_key
|
|
end
|
|
assert_response :no_content
|
|
end
|
|
|
|
test "should store cart" do
|
|
post api_v1_store_cart_path, params: { cart: { ticket_type_id: 1, quantity: 2 }, event_id: @event.id }, as: :json, headers: headers_api_key
|
|
assert_response :success
|
|
assert_equal @event.id, session[:event_id]
|
|
end
|
|
|
|
private
|
|
|
|
def json_response
|
|
JSON.parse(response.body)
|
|
end
|
|
|
|
def headers_api_key
|
|
{ "X-API-Key" => "test_key" }
|
|
end
|
|
end
|