init: hgmj server initial commit

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 16:50:13 +08:00
co-authored by Claude Opus 4.7
commit 625e89c15d
1870 changed files with 254090 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
package mediaService
import (
"testing"
"91jd-server/models/v/mediacontentmod"
"91jd-server/models/v/mediamod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func TestFindExistingMediaContentDramaFallsBackToEpisodeNumber(t *testing.T) {
mediaID := primitive.NewObjectID()
existing := mediacontentmod.MediaContent{
ID: primitive.NewObjectID(),
MediaID: mediaID,
EpisodeNumber: 3,
HashId: "old-hash",
}
episodeLookupCalled := false
got, hashChanged, err := findExistingMediaContent(
mediaID,
mediamod.MediaTypeDrama,
"new-hash",
3,
func(primitive.ObjectID, string) (mediacontentmod.MediaContent, error) {
return mediacontentmod.MediaContent{}, mediacontentmod.MediaContentNotFound
},
func(gotMediaID primitive.ObjectID, gotEpisodeNumber int) (mediacontentmod.MediaContent, error) {
episodeLookupCalled = true
if gotMediaID != mediaID || gotEpisodeNumber != 3 {
t.Fatalf("episode lookup = (%s, %d), want (%s, 3)", gotMediaID, gotEpisodeNumber, mediaID)
}
return existing, nil
},
)
if err != nil {
t.Fatalf("findExistingMediaContent returned error: %v", err)
}
if !episodeLookupCalled {
t.Fatal("episode fallback was not called")
}
if !hashChanged {
t.Fatal("hashChanged = false, want true")
}
if got.ID != existing.ID {
t.Fatalf("content ID = %s, want %s", got.ID, existing.ID)
}
}
func TestFindExistingMediaContentNonDramaDoesNotFallback(t *testing.T) {
episodeLookupCalled := false
_, hashChanged, err := findExistingMediaContent(
primitive.NewObjectID(),
"video",
"new-hash",
3,
func(primitive.ObjectID, string) (mediacontentmod.MediaContent, error) {
return mediacontentmod.MediaContent{}, mediacontentmod.MediaContentNotFound
},
func(primitive.ObjectID, int) (mediacontentmod.MediaContent, error) {
episodeLookupCalled = true
return mediacontentmod.MediaContent{}, nil
},
)
if err != mediacontentmod.MediaContentNotFound {
t.Fatalf("error = %v, want MediaContentNotFound", err)
}
if hashChanged {
t.Fatal("hashChanged = true, want false")
}
if episodeLookupCalled {
t.Fatal("non-drama content used episode fallback")
}
}