@@ -0,0 +1,52 @@
|
||||
package mediacontentser
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"91porn-server/models/v/mediacontentmod"
|
||||
"91porn-server/models/v/mediamod"
|
||||
)
|
||||
|
||||
func TestDramaResponsesDoNotExposeServerProgress(t *testing.T) {
|
||||
tests := map[string]any{
|
||||
"media": mediamod.AppMediaBase{},
|
||||
"episode list": AppMediaContent{},
|
||||
"episode info": MediaContentInfo{},
|
||||
}
|
||||
for name, response := range tests {
|
||||
data, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal %s response: %v", name, err)
|
||||
}
|
||||
if bytes.Contains(data, []byte(`"resume"`)) || bytes.Contains(data, []byte(`"progressSeconds"`)) {
|
||||
t.Fatalf("%s response still exposes server progress: %s", name, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveDramaAccess(t *testing.T) {
|
||||
media := mediamod.Media{FreeEpisode: 1}
|
||||
tests := []struct {
|
||||
name string
|
||||
content mediacontentmod.MediaContent
|
||||
hasBuy bool
|
||||
hasCard bool
|
||||
wantCan bool
|
||||
wantAccess string
|
||||
}{
|
||||
{name: "free episode", content: mediacontentmod.MediaContent{EpisodeNumber: 1, Price: 30, ListenPermission: 1}, wantCan: true, wantAccess: dramaAccessFree},
|
||||
{name: "bought episode", content: mediacontentmod.MediaContent{EpisodeNumber: 2, Price: 30, ListenPermission: 1}, hasBuy: true, wantCan: true, wantAccess: dramaAccessBought},
|
||||
{name: "card episode", content: mediacontentmod.MediaContent{EpisodeNumber: 2, Price: 30, ListenPermission: 1}, hasCard: true, wantCan: true, wantAccess: dramaAccessCard},
|
||||
{name: "locked episode", content: mediacontentmod.MediaContent{EpisodeNumber: 2, Price: 30, ListenPermission: 1}, wantCan: false, wantAccess: dramaAccessCoin},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, canPlay, accessType := ResolveDramaAccess(tt.content, media, tt.hasBuy, tt.hasCard)
|
||||
if canPlay != tt.wantCan || accessType != tt.wantAccess {
|
||||
t.Fatalf("ResolveDramaAccess() = (%v, %q), want (%v, %q)", canPlay, accessType, tt.wantCan, tt.wantAccess)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user