Files
arbeitszeitmessung/Backend/models/absence_test.go
Tom Tröger ba034f1c33
Some checks failed
Tests / Run Go Tests (push) Failing after 1m35s
Arbeitszeitmessung Deploy / Build Webserver (push) Successful in 2m48s
feat: updated docs and added description to files
2026-01-29 18:28:28 +01:00

96 lines
2.4 KiB
Go

package models_test
// all the files with *_test.go are used to test the functions inside the respective file
// the tests are partially complete
import (
"arbeitszeitmessung/helper"
"arbeitszeitmessung/models"
"testing"
"time"
)
var testAbsence = models.Absence{
Day: CatchError(time.Parse(time.DateOnly, "2025-01-01")),
AbwesenheitTyp: models.AbsenceType{},
DateFrom: CatchError(time.Parse(time.DateOnly, "2025-01-01")),
DateTo: CatchError(time.Parse(time.DateOnly, "2025-01-03")),
}
var testKurzarbeit = models.AbsenceType{
Name: "Kurzarbeit",
WorkTime: -1,
}
var testUrlaub = models.AbsenceType{
Name: "Urlaub",
WorkTime: 100,
}
var testUrlaubUntertags = models.AbsenceType{
Name: "Urlaub untertags",
WorkTime: 50,
}
func TestCalcRealWorkTimeDayAbsence(t *testing.T) {
testCases := []struct {
absenceType models.AbsenceType
expectedTime time.Duration
}{
{
absenceType: testUrlaub,
expectedTime: time.Hour * 8,
},
{
absenceType: testUrlaubUntertags,
expectedTime: time.Hour * 4,
},
{
absenceType: testKurzarbeit,
expectedTime: 0,
},
}
for _, tc := range testCases {
t.Run("Calc Absence Worktime: "+tc.absenceType.Name, func(t *testing.T) {
var testCase = testAbsence
testCase.AbwesenheitTyp = tc.absenceType
workTime := testCase.GetWorktime(testUser, models.WorktimeBaseDay, false)
if workTime != tc.expectedTime {
t.Errorf("Calc Worktime Default not working, time should be %s, but was %s", helper.FormatDurationFill(tc.expectedTime, true), helper.FormatDurationFill(workTime, true))
}
})
}
}
func TestCalcRealWorkTimeWeekAbsence(t *testing.T) {
testCases := []struct {
absenceType models.AbsenceType
expectedTime time.Duration
}{
{
absenceType: testUrlaub,
expectedTime: time.Hour * 7,
},
{
absenceType: testUrlaubUntertags,
expectedTime: time.Hour*3 + time.Minute*30,
},
{
absenceType: testKurzarbeit,
expectedTime: 0,
},
}
for _, tc := range testCases {
t.Run("Calc Absence Worktime: "+tc.absenceType.Name, func(t *testing.T) {
var testCase = testAbsence
testCase.AbwesenheitTyp = tc.absenceType
workTime := testCase.GetWorktime(testUser, models.WorktimeBaseWeek, false)
if workTime != tc.expectedTime {
t.Errorf("Calc Worktime Default not working, time should be %s, but was %s", helper.FormatDurationFill(tc.expectedTime, true), helper.FormatDurationFill(workTime, true))
}
})
}
}