[feat]Implement FullCalendarFormatter#event_schedules_to_resources; Add tests

This commit is contained in:
Jimmy 2021-04-26 10:34:14 +08:00 committed by CactusPuppy
parent abe2ea9bb3
commit 4b83ae8be7
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
2 changed files with 46 additions and 8 deletions

View file

@ -5,10 +5,13 @@ require 'spec_helper'
describe FullCalendarFormatter do
let!(:room1) { create(:room) }
let!(:room2) { create(:room) }
let!(:rooms) { [room1, room2] }
let!(:event_schedule1) { create(:event_schedule, room: room1) }
let!(:event_schedule2) { create(:event_schedule, room: room2) }
let!(:event_schedules) { [event_schedule1, event_schedule2] }
describe 'JSON formatting for FullCalendar' do
it 'translates rooms to resources' do
rooms = [room1, room2]
resources = described_class.rooms_to_resources(rooms)
expected_json = [
{
@ -22,5 +25,26 @@ describe FullCalendarFormatter do
].to_json
expect(resources).to eq(expected_json)
end
it 'translates event schedules to resources' do
resources = described_class.event_schedules_to_resources(event_schedules)
expected_json = [
{
id: event_schedule1.event.guid,
title: event_schedule1.event.title,
start: event_schedule1.start_time,
end: event_schedule1.end_time,
source: room1.guid
},
{
id: event_schedule2.event.guid,
title: event_schedule2.event.title,
start: event_schedule2.start_time,
end: event_schedule2.end_time,
source: room2.guid
}
].to_json
expect(resources).to eq(expected_json)
end
end
end