Started off well
This commit is contained in:
108
Tests/MusicBrainzTests/ExtendedSearchTests.swift
Normal file
108
Tests/MusicBrainzTests/ExtendedSearchTests.swift
Normal file
@@ -0,0 +1,108 @@
|
||||
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<Area>.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<ReleaseGroup>.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<Label>.self, from: json)
|
||||
|
||||
#expect(response.count == 1)
|
||||
#expect(response.entities.count == 1)
|
||||
#expect(response.entities[0].name == "Ninja Tune")
|
||||
#expect(response.entities[0].labelCode == 12885)
|
||||
}
|
||||
|
||||
@Test func testURLSearchDecoding() throws {
|
||||
let json = """
|
||||
{
|
||||
"created": "2024-05-20T12:00:00.000Z",
|
||||
"count": 1,
|
||||
"offset": 0,
|
||||
"urls": [
|
||||
{
|
||||
"id": "b663423b-9b54-4067-9674-fffaecf68851",
|
||||
"resource": "http://www.madonna.com/",
|
||||
"score": 100
|
||||
}
|
||||
]
|
||||
}
|
||||
""".data(using: .utf8)!
|
||||
|
||||
let response = try JSONDecoder().decode(SearchResponse<URLReference>.self, from: json)
|
||||
|
||||
#expect(response.count == 1)
|
||||
#expect(response.entities.count == 1)
|
||||
#expect(response.entities[0].resource == "http://www.madonna.com/")
|
||||
}
|
||||
Reference in New Issue
Block a user