Skip to content
Snippets Groups Projects
Unverified Commit d5a0a2ec authored by Sébastien Gaya's avatar Sébastien Gaya Committed by GitHub
Browse files

Merge pull request #1522 from noesya/fix-and-tests-events

fix and tests events
parents dee54671 504c1c11
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ module Communication::Website::Agenda::Event::WithCal
def cal
@cal ||= AddToCalendar::URLs.new(
start_datetime: cal_from_time,
start_datetime: cal_from_time,
end_datetime: cal_to_time,
timezone: timezone.name,
all_day: cal_all_day,
......@@ -21,6 +21,9 @@ module Communication::Website::Agenda::Event::WithCal
end
def cal_to_time
# Si all_day == true et qu'on ne transmet pas de date de fin, l'événement sera considéré comme un événement d'une journée
# On peut donc early return selon ces conditions
return if cal_all_day && from_day == to_day
to_day.nil? ? cal_to_time_with_no_end_day
: cal_to_time_with_end_day
end
......@@ -37,7 +40,7 @@ module Communication::Website::Agenda::Event::WithCal
def cal_to_time_with_end_day
# Soit on a 1 heure de fin, et tout est simple
cal_end_time = to_hour
cal_end_time = to_hour
# Soit on n'en a pas, mais on a 1 heure de début, donc on ajoute 1 heure pour éviter les événements sans durée
cal_end_time ||= from_hour + 1.hour if from_hour
# Si rien n'a marché, on a nil
......
......@@ -43,7 +43,102 @@
require "test_helper"
class Communication::Website::Agenda::EventTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "valid cal file with specific dates and hours" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: Date.tomorrow + 1.day,
to_hour: "19:00"
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file with specific hours on the same day" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: Date.tomorrow,
to_hour: "19:00"
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file with specific hours but no end date" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: nil,
to_hour: "19:00"
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file with specific dates but no end hour" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: Date.tomorrow + 1.day,
to_hour: nil
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file on same day but no end hour" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: Date.tomorrow,
to_hour: nil
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file on same day but no hours" do
event = new_event(
from_day: Date.tomorrow,
from_hour: nil,
to_day: Date.tomorrow,
to_hour: nil
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file with specific dates but no hours" do
event = new_event(
from_day: Date.tomorrow,
from_hour: nil,
to_day: Date.tomorrow + 1.day,
to_hour: nil
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
test "valid cal file but no end" do
event = new_event(
from_day: Date.tomorrow,
from_hour: "09:00",
to_day: nil,
to_hour: nil
)
assert(event.valid?)
assert_nothing_raised { event.cal }
end
protected
def new_event(**options)
website_with_github.agenda_events.new(
title: "An event",
university_id: website_with_github.university_id,
language_id: website_with_github.default_language_id,
**options
)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment