-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunit_ArtistApiTests.swift
164 lines (154 loc) · 6.1 KB
/
unit_ArtistApiTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// unit_ArtistApiTests.swift
// YM-macTests
//
// Created by Developer on 26.07.2021.
//
import XCTest
#if canImport(YmuzApiMac)
@testable import YmuzApiMac
#endif
#if canImport(YmuzApi)
@testable import YmuzApi
#endif
class unit_ArtistApiTests: XCTestCase {
var client: YMClient!
var device: YMDevice {get {return TestConstants.device}}
var apiLang: ApiLanguage {get {return TestConstants.apiLang}}
var token: String {get {return TestCredentials.token}}
var xToken: String {get {return TestCredentials.xToken}}
var uid: Int {get {return TestCredentials.uid}}
override func setUp() {
client = YMClient.initialize(device: device, lang: apiLang, uid: uid, token: token, xToken: xToken)
}
override func tearDown() {
client = nil
}
func testArtistSingleResponse() {
let artistId = 4699882
let exp = self.expectation(description: "Request time-out expectation")
client.getArtists(artistIds: [String(artistId)]) { result in
do {
let artists = try result.get()
XCTAssertNotNil(artists, "Artist is nil")
XCTAssert(artists.count > 0, "Artists' array is empty")
XCTAssert(artists[0].id == artistId, "Incorrect parsing artist object")
} catch {
print(error)
XCTAssert(false, "Empty artist object: " + error.localizedDescription)
}
exp.fulfill()
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testArtistImgResponse() {
let artistId = 4699882
let exp = self.expectation(description: "Request time-out expectation")
client.getArtists(artistIds: [String(artistId)]) { result in
do {
let artists = try result.get()
XCTAssertNotNil(artists, "Artist is nil")
XCTAssert(artists.count > 0, "Artists' array is empty")
XCTAssert(artists[0].id == artistId, "Incorrect parsing artist object")
artists[0].cover?.downloadImg {
result2 in
do {
let data = try result2.get()
XCTAssertTrue(data.count > 0, "Empty artist image data")
} catch {
print(error)
XCTAssert(false, "Empty artist cover object: " + error.localizedDescription)
}
exp.fulfill()
}
} catch {
print(error)
XCTAssert(false, "Empty artist object: " + error.localizedDescription)
}
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testArtistShortInfoResponse() {
let artistId = 4699882
let exp = self.expectation(description: "Request time-out expectation")
client.getArtistShortInfo(artistId: String(artistId)) { result in
do {
let artist = try result.get()
XCTAssert(artist.artist?.id == artistId, "Incorrect parsing artist object")
} catch {
print(error)
XCTAssert(false, "Empty artist object: " + error.localizedDescription)
}
exp.fulfill()
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testArtistTracksResponse() {
let artistId = 4699882
let exp = self.expectation(description: "Request time-out expectation")
client.getArtistTracks(artistId: String(artistId)) { result in
do {
let tracks = try result.get()
XCTAssertTrue(tracks.pager != nil, "Artist tracks pager is nil")
if let g_pager = tracks.pager {
XCTAssertTrue(g_pager.page == 0, "Actual page index doesn't match with actual")
XCTAssertTrue(20 == g_pager.perPage || (g_pager.perPage == g_pager.total && g_pager.perPage <= 20), "Page size is incorrectly parsed")
}
} catch {
print(error)
XCTAssert(false, "Empty artist tracks object: " + error.localizedDescription)
}
exp.fulfill()
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testArtistDirectAlbumsResponse() {
let artistId = 4699882
let exp = self.expectation(description: "Request time-out expectation")
client.getArtistDirectAlbums(artistId: String(artistId), sortBy: .year) { result in
do {
let albums = try result.get()
XCTAssertTrue(albums.pager != nil, "Artist direct albums pager is nil")
if let g_pager = albums.pager {
XCTAssertTrue(g_pager.page == 0, "Actual page index doesn't match with actual")
XCTAssertTrue(20 == g_pager.perPage || (g_pager.perPage == g_pager.total && g_pager.perPage <= 20), "Page size is incorrectly parsed")
}
} catch {
print(error)
XCTAssert(false, "Empty artist direct albums object: " + error.localizedDescription)
}
exp.fulfill()
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
}