Everything works well and good structure.
This commit is contained in:
@@ -106,3 +106,56 @@ import Testing
|
||||
#expect(response.entities.count == 1)
|
||||
#expect(response.entities[0].resource == "http://www.madonna.com/")
|
||||
}
|
||||
|
||||
@Test func testCoverArtDecoding() throws {
|
||||
let json = """
|
||||
{
|
||||
"images": [
|
||||
{
|
||||
"image": "http://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/3125412512.jpg",
|
||||
"thumbnails": {
|
||||
"small": "http://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/3125412512-250.jpg",
|
||||
"large": "http://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/3125412512-500.jpg"
|
||||
},
|
||||
"types": ["Front"],
|
||||
"front": true,
|
||||
"back": false,
|
||||
"edit": 12345,
|
||||
"comment": "",
|
||||
"id": "3125412512"
|
||||
}
|
||||
],
|
||||
"release": "https://musicbrainz.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc"
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let response = try JSONDecoder().decode(CoverArtResponse.self, from: json)
|
||||
|
||||
#expect(response.images.count == 1)
|
||||
#expect(response.images[0].front == true)
|
||||
#expect(response.frontImage?.image == "http://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/3125412512.jpg")
|
||||
#expect(response.images[0].thumbnails["small"] == "http://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/3125412512-250.jpg")
|
||||
}
|
||||
|
||||
@Test func testArtistImageExtraction() throws {
|
||||
let json = """
|
||||
{
|
||||
"id": "f27ec8db-af05-4f36-916e-3d57f91ecf5e",
|
||||
"name": "Michael Jackson",
|
||||
"sort-name": "Jackson, Michael",
|
||||
"relations": [
|
||||
{
|
||||
"type": "image",
|
||||
"direction": "forward",
|
||||
"url": {
|
||||
"id": "123",
|
||||
"resource": "https://commons.wikimedia.org/wiki/File:Michael_Jackson_1984.jpg"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let artist = try JSONDecoder().decode(Artist.self, from: json)
|
||||
#expect(artist.imageURL?.absoluteString == "https://commons.wikimedia.org/wiki/File:Michael_Jackson_1984.jpg")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user