Fix Album model to match Python reference
- Labels: changed from []Label to []LabelOrString (API returns both objects and strings) - Trailer: changed from *TrailerInfo to *AlbumTrailerStatus (Python has AlbumTrailerStatus with only 'available' field) - Added LabelOrString type with custom UnmarshalJSON - Added AlbumTrailerStatus type with Available field
This commit is contained in:
1 parent
6312c24b0f
commit
277a3e6924
2 files changed
+124
-58
No files matched your search
@@ -30,7 +30,7 @@ func TestAlbum_DeJSON(t *testing.T) {
|
||||
"best": {"tracks": [{"id": "bt1", "title": "Best Track", "duration_ms": 200000}]},
|
||||
"track_positions": [{"revision": 1, "timestamp": "2023-01-01T00:00:00Z", "position": 1, "from_cache": false}],
|
||||
"similar_albums": [{"id": "sim1", "title": "Similar Album", "cover_uri": "https://example.com/sim.jpg", "year": 2022}],
|
||||
"trailer": {"preview_uri": "https://example.com/preview.mp3", "track_id": "t1", "album_id": "123", "duration": 30}
|
||||
"trailer": {"available": true}
|
||||
}`)
|
||||
|
||||
album := &Album{BaseModel: *NewBaseModel(client)}
|
||||
@@ -101,8 +101,8 @@ func TestAlbum_DeJSON(t *testing.T) {
|
||||
if len(resultAlbum.Labels) != 1 {
|
||||
t.Errorf("Expected 1 label, got %d", len(resultAlbum.Labels))
|
||||
}
|
||||
if resultAlbum.Labels[0].Name != "Label 1" {
|
||||
t.Errorf("Expected label name 'Label 1', got '%s'", resultAlbum.Labels[0].Name)
|
||||
if resultAlbum.Labels[0].String() != "Label 1" {
|
||||
t.Errorf("Expected label name 'Label 1', got '%s'", resultAlbum.Labels[0].String())
|
||||
}
|
||||
|
||||
// Test volumes
|
||||
@@ -164,17 +164,8 @@ func TestAlbum_DeJSON(t *testing.T) {
|
||||
if resultAlbum.Trailer == nil {
|
||||
t.Fatal("Expected Trailer to be non-nil")
|
||||
}
|
||||
if resultAlbum.Trailer.PreviewURI != "https://example.com/preview.mp3" {
|
||||
t.Errorf("Expected PreviewURI 'https://example.com/preview.mp3', got '%s'", resultAlbum.Trailer.PreviewURI)
|
||||
}
|
||||
if resultAlbum.Trailer.TrackID != "t1" {
|
||||
t.Errorf("Expected TrackID 't1', got '%s'", resultAlbum.Trailer.TrackID)
|
||||
}
|
||||
if resultAlbum.Trailer.AlbumID != "123" {
|
||||
t.Errorf("Expected AlbumID '123', got '%s'", resultAlbum.Trailer.AlbumID)
|
||||
}
|
||||
if resultAlbum.Trailer.Duration != 30 {
|
||||
t.Errorf("Expected Duration 30, got %d", resultAlbum.Trailer.Duration)
|
||||
if !resultAlbum.Trailer.Available {
|
||||
t.Errorf("Expected Trailer.Available true, got false")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,50 +299,38 @@ func TestAlbumMeta_DeList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrailerInfo_DeJSON(t *testing.T) {
|
||||
func TestAlbumTrailerStatus_DeJSON(t *testing.T) {
|
||||
client := newMockClient()
|
||||
data := []byte(`{
|
||||
"preview_uri": "https://example.com/preview.mp3",
|
||||
"track_id": "track123",
|
||||
"album_id": "album456",
|
||||
"duration": 45
|
||||
"available": true
|
||||
}`)
|
||||
|
||||
trailer := &TrailerInfo{BaseModel: *NewBaseModel(client)}
|
||||
result, err := trailer.DeJSON(data, client)
|
||||
status := &AlbumTrailerStatus{BaseModel: *NewBaseModel(client)}
|
||||
result, err := status.DeJSON(data, client)
|
||||
if err != nil {
|
||||
t.Fatalf("DeJSON failed: %v", err)
|
||||
}
|
||||
|
||||
resultTrailer := result.(*TrailerInfo)
|
||||
if resultTrailer.PreviewURI != "https://example.com/preview.mp3" {
|
||||
t.Errorf("Expected PreviewURI 'https://example.com/preview.mp3', got '%s'", resultTrailer.PreviewURI)
|
||||
}
|
||||
if resultTrailer.TrackID != "track123" {
|
||||
t.Errorf("Expected TrackID 'track123', got '%s'", resultTrailer.TrackID)
|
||||
}
|
||||
if resultTrailer.AlbumID != "album456" {
|
||||
t.Errorf("Expected AlbumID 'album456', got '%s'", resultTrailer.AlbumID)
|
||||
}
|
||||
if resultTrailer.Duration != 45 {
|
||||
t.Errorf("Expected Duration 45, got %d", resultTrailer.Duration)
|
||||
resultStatus := result.(*AlbumTrailerStatus)
|
||||
if !resultStatus.Available {
|
||||
t.Errorf("Expected Available true, got false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrailerInfo_DeList(t *testing.T) {
|
||||
func TestAlbumTrailerStatus_DeList(t *testing.T) {
|
||||
client := newMockClient()
|
||||
data := []byte(`[
|
||||
{"preview_uri": "https://example.com/preview1.mp3", "track_id": "t1", "album_id": "a1", "duration": 30},
|
||||
{"preview_uri": "https://example.com/preview2.mp3", "track_id": "t2", "album_id": "a2", "duration": 45}
|
||||
{"available": true},
|
||||
{"available": false}
|
||||
]`)
|
||||
|
||||
trailer := &TrailerInfo{BaseModel: *NewBaseModel(client)}
|
||||
result, err := trailer.DeList(data, client)
|
||||
status := &AlbumTrailerStatus{BaseModel: *NewBaseModel(client)}
|
||||
result, err := status.DeList(data, client)
|
||||
if err != nil {
|
||||
t.Fatalf("DeList failed: %v", err)
|
||||
}
|
||||
|
||||
if len(result) != 2 {
|
||||
t.Errorf("Expected 2 trailers, got %d", len(result))
|
||||
t.Errorf("Expected 2 statuses, got %d", len(result))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user