//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format. //Copyright (C) 2024 HTWKalender support@htwkalender.de //This program is free software: you can redistribute it and/or modify //it under the terms of the GNU Affero General Public License as published by //the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. //This program is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU Affero General Public License for more details. //You should have received a copy of the GNU Affero General Public License //along with this program. If not, see . package ical import ( "github.com/jordic/goics" "htwkalender/model" mockTime "htwkalender/service/functions/time" "reflect" "testing" "time" ) func TestIcalModel_EmitICal(t *testing.T) { type fields struct { Events model.Events Mapping map[string]model.FeedCollection } tests := []struct { name string fields fields want *goics.Component }{ { name: "Test EmitICal", fields: fields{ Events: model.Events{ { UUID: "123", Name: "Test", EventType: "Test", Notes: "Test", Prof: "Test", Rooms: "Test", BookedAt: "Test", }, }, Mapping: map[string]model.FeedCollection{ "123": { UUID: "123", Name: "Test", Course: "Test", UserDefinedName: "Test", }, }, }, want: &goics.Component{ Tipo: "VCALENDAR", Elements: []goics.Componenter{ &goics.Component{ Tipo: "VTIMEZONE", Elements: []goics.Componenter{ &HtwkalenderComponent{ Component: &goics.Component{ Tipo: "STANDARD", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTART": {"19701025T030000"}, "RRULE": {"FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU"}, "TZOFFSETFROM": {"+0200"}, "TZOFFSETTO": {"+0100"}, "TZNAME": {"CET"}, }, }, }, &HtwkalenderComponent{ Component: &goics.Component{ Tipo: "DAYLIGHT", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTART": {"19700329T020000"}, "TZOFFSETFROM": {"+0100"}, "TZOFFSETTO": {"+0200"}, "TZNAME": {"CEST"}, "RRULE": {"FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU"}, }, }, }, }, Properties: map[string][]string{ "TZID": {"EUROPE/BERLIN"}, }, }, &goics.Component{ Tipo: "VEVENT", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTAMP": {"20231201T000000Z"}, "UID": {"a8d627d93f518e9096b6f40e36d27b7660fa26d318ef1adc43da750e49ebe4be@htwkalender.de"}, "DTEND": {"00010101T000000Z"}, "DTSTART": {"00010101T000000Z"}, "SUMMARY": {"Test"}, "DESCRIPTION": {"Notizen: Test\nProf: Test\nTyp: Test\n"}, "LOCATION": {"Test"}, }, }, }, Properties: map[string][]string{ "PRODID": {"-//HTWK Kalender//htwkalender.de//DE"}, "VERSION": {"2.0"}, "CALSCALE": {"GREGORIAN"}, "TZID": {"EUROPE/BERLIN"}, "X-WR-CALNAME": {"HTWK Kalender"}, "X-WR-TIMEZONE": {"EUROPE/BERLIN"}, }, }, }, { name: "Test Similar Events like Sport Courses", fields: fields{ Events: model.Events{ { UUID: "123", Name: "Test", Course: "Test", EventType: "Test", Notes: "Test", Prof: "Test", Rooms: "ZU430", BookedAt: "Test", Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)), End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 1, 0, 0, 0, time.UTC)), }, { UUID: "123", Name: "Test", Course: "Test", EventType: "Test", Notes: "Test", Prof: "Test", Rooms: "ZU221", BookedAt: "Test", Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)), End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 1, 0, 0, 0, time.UTC)), }, }, Mapping: map[string]model.FeedCollection{ "123": { UUID: "123", Name: "Test", Course: "Test", UserDefinedName: "UserDefinedName", }, }, }, want: &goics.Component{ Tipo: "VCALENDAR", Elements: []goics.Componenter{ &goics.Component{ Tipo: "VTIMEZONE", Elements: []goics.Componenter{ &HtwkalenderComponent{ Component: &goics.Component{ Tipo: "STANDARD", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTART": {"19701025T030000"}, "RRULE": {"FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU"}, "TZOFFSETFROM": {"+0200"}, "TZOFFSETTO": {"+0100"}, "TZNAME": {"CET"}, }, }, }, &HtwkalenderComponent{ Component: &goics.Component{ Tipo: "DAYLIGHT", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTART": {"19700329T020000"}, "TZOFFSETFROM": {"+0100"}, "TZOFFSETTO": {"+0200"}, "TZNAME": {"CEST"}, "RRULE": {"FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU"}, }, }, }, }, Properties: map[string][]string{ "TZID": {"EUROPE/BERLIN"}, }, }, &goics.Component{ Tipo: "VEVENT", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTAMP": {"20231201T000000Z"}, "UID": {"b52a7a081f46eeba9b402114493278a34a48b572c84e53d7ac4da9dea15cdff2@htwkalender.de"}, "DTEND": {"20231201T010000Z"}, "DTSTART": {"20231201T000000Z"}, "SUMMARY": {"UserDefinedName"}, "DESCRIPTION": {"Notizen: Test\nProf: Test\nGruppe: Test\nTyp: Test\n"}, "LOCATION": {"ZU430"}, }, }, &goics.Component{ Tipo: "VEVENT", Elements: []goics.Componenter{}, Properties: map[string][]string{ "DTSTAMP": {"20231201T000000Z"}, "UID": {"5e946c0c4474bc6e6337262093e3ef31477e026bbc6bab398d755b002506d9d7@htwkalender.de"}, "DTEND": {"20231201T010000Z"}, "DTSTART": {"20231201T000000Z"}, "SUMMARY": {"UserDefinedName"}, "DESCRIPTION": {"Notizen: Test\nProf: Test\nGruppe: Test\nTyp: Test\n"}, "LOCATION": {"ZU221"}, }, }, }, Properties: map[string][]string{ "PRODID": {"-//HTWK Kalender//htwkalender.de//DE"}, "VERSION": {"2.0"}, "CALSCALE": {"GREGORIAN"}, "TZID": {"EUROPE/BERLIN"}, "X-WR-CALNAME": {"HTWK Kalender"}, "X-WR-TIMEZONE": {"EUROPE/BERLIN"}, }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { icalModel := IcalModel{ Events: tt.fields.Events, Mapping: tt.fields.Mapping, } mockClock := mockTime.MockClock{ NowTime: time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC), } if got := generateIcalEmit(icalModel, mockClock); !reflect.DeepEqual(got, tt.want) { t.Errorf("EmitICal() = %v, want %v", got, tt.want) } }) } }