78 lines
2.2 KiB
Go
78 lines
2.2 KiB
Go
package utils_test
|
|
|
|
import (
|
|
"os"
|
|
|
|
"clintonambulance.com/calculate_negative_points/internal/utils"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("ParseXLSContent", func() {
|
|
It("parses employees and their shifts from the test XLS file", func() {
|
|
content, err := os.ReadFile("testdata/test.xls")
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
employees, err := utils.ParseXLSContent(content)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(employees).To(HaveLen(2))
|
|
|
|
By("parsing the first employee")
|
|
Expect(employees[0].Name).To(Equal("Howe, Eugene"))
|
|
Expect(employees[0].Worked()).To(BeTrue())
|
|
Expect(employees[0].Shifts).To(HaveLen(2))
|
|
Expect(employees[0].Shifts[0]).To(Equal(utils.Shift{
|
|
EarningCode: "MEET",
|
|
Description: "Meetings",
|
|
Hours: 1.75,
|
|
}))
|
|
Expect(employees[0].Shifts[0].CountsAsWorked()).To(BeFalse())
|
|
Expect(employees[0].Shifts[1]).To(Equal(utils.Shift{
|
|
EarningCode: "Reg",
|
|
Description: "Regular Hours",
|
|
Hours: 125.75,
|
|
}))
|
|
Expect(employees[0].Shifts[1].CountsAsWorked()).To(BeTrue())
|
|
|
|
By("parsing the second employee with multiple shift categories")
|
|
Expect(employees[1].Name).To(Equal("User, Test"))
|
|
Expect(employees[1].Shifts).To(HaveLen(4))
|
|
Expect(employees[1].Shifts[0]).To(Equal(utils.Shift{
|
|
EarningCode: "MEET",
|
|
Description: "Meetings",
|
|
Hours: 2.00,
|
|
}))
|
|
Expect(employees[1].Shifts[1]).To(Equal(utils.Shift{
|
|
EarningCode: "Reg",
|
|
Description: "Regular Hours",
|
|
Hours: 134.00,
|
|
}))
|
|
Expect(employees[1].Shifts[2]).To(Equal(utils.Shift{
|
|
EarningCode: "Holiday",
|
|
Description: "Holiday Hours",
|
|
Hours: 8.00,
|
|
}))
|
|
Expect(employees[1].Shifts[3]).To(Equal(utils.Shift{
|
|
EarningCode: "PTO",
|
|
Description: "Paid Time Off",
|
|
Hours: 12.00,
|
|
}))
|
|
})
|
|
|
|
It("skips category header rows (colspan rows)", func() {
|
|
content, err := os.ReadFile("testdata/test.xls")
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
employees, err := utils.ParseXLSContent(content)
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(employees).To(HaveLen(2))
|
|
})
|
|
|
|
It("returns an empty slice for empty content", func() {
|
|
employees, err := utils.ParseXLSContent([]byte(""))
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(employees).To(BeEmpty())
|
|
})
|
|
})
|