import Foundation import Testing @testable import MusicBrainz @Test func testAreaSearchDecoding() throws { let json = """ { "created": "2024-05-20T12:00:00.000Z", "count": 1, "offset": 0, "areas": [ { "id": "f03ed396-3f4d-4ef4-81b0-7c03c46961e2", "type": "City", "score": 100, "name": "London", "sort-name": "London", "life-span": { "ended": false } } ] } """.data(using: .utf8)! let response = try JSONDecoder().decode(SearchResponse.self, from: json) #expect(response.count == 1) #expect(response.entities.count == 1) #expect(response.entities[0].name == "London") #expect(response.entities[0].score == 100) } @Test func testReleaseGroupSearchDecoding() throws { let json = """ { "created": "2024-05-20T12:00:00.000Z", "count": 1, "offset": 0, "release-groups": [ { "id": "1b022e01-4da6-387b-8658-8678046e4ccc", "score": 100, "primary-type": "Album", "title": "Nevermind", "artist-credit": [{ "name": "Nirvana" }] } ] } """.data(using: .utf8)! let response = try JSONDecoder().decode(SearchResponse.self, from: json) #expect(response.count == 1) #expect(response.entities.count == 1) #expect(response.entities[0].title == "Nevermind") #expect(response.entities[0].primaryType == "Album") #expect(response.entities[0].artistCredit?[0].name == "Nirvana") } @Test func testLabelSearchDecoding() throws { let json = """ { "created": "2024-05-20T12:00:00.000Z", "count": 1, "offset": 0, "labels": [ { "id": "79239441-bfd5-4981-a70c-55c3f15c1287", "type": "Production", "score": 100, "name": "Ninja Tune", "label-code": 12885, "country": "GB" } ] } """.data(using: .utf8)! let response = try JSONDecoder().decode(SearchResponse