navidrome/utils/time_test.go
Kendall Garner 36ed880e61
fix(scanner): always refresh folder image time when adding first image (#3764)
* fix(scanner): Always refresh folder image time when adding first image

Currently, the `images_updated_at` field is only set to the image modification time.
However, in cases where a new image is added _and_ said image is older than the folder mod time, the field is not updated properly.

In this the case where `images_updated_at` is null (no images were ever added) and a new images is found, use the folder modification time instead of image modification time.

**Note**, this doesn't handle cases such as replacing a newer image with an older one.

* simplify image update at

* we don't want to set imagesUpdatedAt when there's no images in the folder

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
Co-authored-by: Deluan <deluan@navidrome.org>
2025-03-06 22:16:37 -05:00

28 lines
754 B
Go

package utils_test
import (
"time"
"github.com/navidrome/navidrome/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("TimeNewest", func() {
It("returns zero time when no times are provided", func() {
Expect(utils.TimeNewest()).To(Equal(time.Time{}))
})
It("returns the time when only one time is provided", func() {
t1 := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
Expect(utils.TimeNewest(t1)).To(Equal(t1))
})
It("returns the newest time when multiple times are provided", func() {
t1 := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
t2 := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
t3 := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
Expect(utils.TimeNewest(t1, t2, t3)).To(Equal(t2))
})
})