-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunit_AlbumApiTests.swift
173 lines (163 loc) · 6.5 KB
/
unit_AlbumApiTests.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
165
166
167
168
169
170
171
172
173
//
// unit_AlbumApiTests.swift
// YM-macTests
//
// Created by Developer on 21.07.2021.
//
import XCTest
#if canImport(YmuzApiMac)
@testable import YmuzApiMac
#endif
#if canImport(YmuzApi)
@testable import YmuzApi
#endif
class unit_AlbumApiTests: 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 testAlbumSingleResponse() {
let albumId = 4158732
let exp = self.expectation(description: "Request time-out expectation")
client.getAlbums(albumIds: [String(albumId)]) { result in
do {
let albums = try result.get()
XCTAssertNotNil(albums, "Album is nil")
XCTAssert(albums.count > 0, "Albums' array is empty")
XCTAssert(albums[0].id == albumId, "Incorrect parsing album object")
XCTAssert(albums[0].error == nil || albums[0].error == "", "Album not found")
} catch {
print(error)
XCTAssert(false, "Empty album 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 testAlbumCoverResponse() {
let albumId = 4158732
let exp = self.expectation(description: "Request time-out expectation")
client.getAlbums(albumIds: [String(albumId)]) { result in
do {
let albums = try result.get()
XCTAssertNotNil(albums, "Album is nil")
XCTAssert(albums.count > 0, "Albums' array is empty")
XCTAssert(albums[0].id == albumId, "Incorrect parsing album object")
XCTAssert(albums[0].error == nil || albums[0].error == "", "Album not found")
albums[0].downloadCoverImg {
result2 in
do {
let cover = try result2.get()
XCTAssertTrue(cover.count > 0, "Album cover is empty. Unable to test")
} catch {
print(error)
XCTAssert(false, "Empty album cover data: " + error.localizedDescription)
}
exp.fulfill()
}
} catch {
print(error)
XCTAssert(false, "Empty album object: " + error.localizedDescription)
}
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testAlbumOgImgResponse() {
let albumId = 4158732
let exp = self.expectation(description: "Request time-out expectation")
client.getAlbums(albumIds: [String(albumId)]) { result in
do {
let albums = try result.get()
XCTAssertNotNil(albums, "Album is nil")
XCTAssert(albums.count > 0, "Albums' array is empty")
XCTAssert(albums[0].id == albumId, "Incorrect parsing album object")
XCTAssert(albums[0].error == nil || albums[0].error == "", "Album not found")
albums[0].downloadOgImage {
result2 in
do {
let og = try result2.get()
XCTAssertTrue(og.count > 0, "Album cover is empty. Unable to test")
} catch {
print(error)
XCTAssert(false, "Empty album cover data: " + error.localizedDescription)
}
exp.fulfill()
}
} catch {
print(error)
XCTAssert(false, "Empty album object: " + error.localizedDescription)
}
}
waitForExpectations(timeout: 5) { error in
if let g_error = error
{
print(g_error)
XCTAssert(false, "Timeout error: " + g_error.localizedDescription)
}
}
}
func testNewAlbumsResponse() {
let exp = self.expectation(description: "Request time-out expectation")
client.getNewAlbums{ result in
do {
let albums = try result.get()
XCTAssertTrue(albums.type.compare("new-releases") == .orderedSame, "Response doesn't contain new albums")
XCTAssertTrue(albums.newReleases?.count != 0, "New albums' array is empty")
} catch {
print(error)
XCTAssert(false, "Empty new albums array 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 testAlbumWitthTracksResponse() {
let albumId = 4158732
let exp = self.expectation(description: "Request time-out expectation")
client.getAlbumWithTracksData(albumId: String(albumId)) { result in
do {
let album = try result.get()
XCTAssert(album.id == albumId, "Incorrect parsing album object")
XCTAssertTrue(album.volumes?.count != 0, "No volumes info with tracks in the album")
XCTAssertTrue(album.volumes?[0].count != 0, "No tracks info in the album inside the volume")
} catch {
print(error)
XCTAssert(false, "Empty album 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)
}
}
}
}