1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

Fix a bug: trainings monitoring is not available

This commit is contained in:
Sylvain 2022-08-23 15:54:37 +02:00
parent faae719fef
commit f7261043b5
4 changed files with 40 additions and 5 deletions

View File

@ -7,6 +7,7 @@
- Use union type instead of enum for SettingName
- Fix a bug: wrong variable reference in `SingleSignOnConcern:Merge_form_sso`
- Fix a bug: wrong focus behavior on text editor
- Fix a bug: trainings monitoring is not available
## v5.4.15 2022 August 1

View File

@ -52,7 +52,13 @@ class API::TrainingsController < API::ApiController
authorize Training
@training = Training.find(params[:id])
@availabilities = @training.availabilities
.includes(slots: { slots_reservations: { reservations: { statistic_profile: [:trainings, user: [:profile]] } } })
.includes(slots: {
slots_reservations: {
reservation: {
statistic_profile: [:trainings, { user: [:profile] }]
}
}
})
.where('slots_reservations.canceled_at': nil)
.order('availabilities.start_at DESC')
end

View File

@ -1,11 +1,13 @@
# frozen_string_literal: true
json.extract! @training, :id, :name, :description, :machine_ids, :nb_total_places, :public_page
json.availabilities @availabilities do |a|
json.id a.id
json.start_at a.start_at.iso8601
json.end_at a.end_at.iso8601
json.reservation_users a.slots.map do |slot|
json.id slot.reservations.first.statistic_profile.user_id
json.full_name slot.reservations.first.statistic_profile&.user&.profile&.full_name
json.is_valid slot.reservations.first.statistic_profile.trainings.include?(@training)
json.reservation_users a.slots.map(&:slots_reservations).flatten.map do |sr|
json.id sr.reservation.statistic_profile.user_id
json.full_name sr.reservation.statistic_profile.user&.profile&.full_name
json.is_valid sr.reservation.statistic_profile.trainings&.include?(@training)
end
end

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
require 'test_helper'
module Trainings; end
class Trainings::AvailabilitiesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'get trainings availabilities list' do
training = Training.find(1)
get "/api/trainings/#{training.id}/availabilities"
# Check response format & status
assert_equal 200, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the correct training was returned
result = json_response(response.body)
assert_equal training.id, result[:id], 'training id does not match'
assert_not_empty result[:availabilities], 'no training availabilities were returned'
end
end