Skip to content

Commit db390f4

Browse files
committed
minor fixes
1 parent fbc67cf commit db390f4

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

HttpUtility/HURequest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
import Foundation
1010

11-
protocol Request {
11+
public protocol Request {
1212
var url: URL { get set }
1313
var method: HUHttpMethods {get set}
1414
}
1515

1616
public struct HURequest : Request {
17-
var url: URL
18-
var method: HUHttpMethods
17+
public var url: URL
18+
public var method: HUHttpMethods
1919
var requestBody: Data? = nil
2020

2121
init(withUrl url: URL, forHttpMethod method: HUHttpMethods, requestBody: Data? = nil) {
@@ -27,8 +27,8 @@ public struct HURequest : Request {
2727

2828
// the HUMedia will be part of next release
2929
public struct HUMultiPartRequest : Request {
30-
var url: URL
31-
var method: HUHttpMethods
30+
public var url: URL
31+
public var method: HUHttpMethods
3232
var request : Encodable
3333
//var media : [HUMedia]? = nil
3434
}

HttpUtility/HttpUtility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class HttpUtility
6969
do {
7070
return try decoder.decode(responseType, from: data)
7171
}catch let error {
72-
debugPrint("deocding error =>\(error.localizedDescription)")
72+
debugPrint("error while decoding JSON response =>\(error.localizedDescription)")
7373
}
7474
return nil
7575
}

HttpUtilityTests/IntegrationTests/HttpUtilityIntegrationTests.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,30 @@
99
import XCTest
1010
@testable import HttpUtility
1111

12-
13-
struct MyStruct : Encodable
12+
struct MultiPartPostRequest : Encodable
1413
{
1514
let name, lastName: String
1615
}
1716

1817
class HttpUtilityIntegrationTests: XCTestCase {
1918

20-
private typealias Employees = [EmployeeResponse]
2119
private let _utility = HttpUtility.shared
2220

2321
func test_getApiData_With_Valid_Request_Returns_Success()
2422
{
2523
// ARRANGE
26-
let requestUrl = URL(string: "http://demo0333988.mockable.io/Employees")
24+
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/api/Animal/GetAnimals")
2725
let expectation = XCTestExpectation(description: "Data received from server")
2826
let request = HURequest(withUrl: requestUrl!, forHttpMethod: .get)
2927

30-
_utility.request(huRequest: request, resultType: Employees.self) { (response) in
28+
_utility.request(huRequest: request, resultType: AnimalResponse.self) { (response) in
3129
switch response
3230
{
33-
case .success(let employee):
31+
case .success(let animal):
3432

3533
// ASSERT
36-
XCTAssertNotNil(employee)
37-
XCTAssertTrue(employee?.count == 2)
34+
XCTAssertNotNil(animal)
35+
XCTAssertNotNil(animal?.data)
3836

3937
case .failure(let error):
4038

@@ -168,7 +166,7 @@ class HttpUtilityIntegrationTests: XCTestCase {
168166
let expectation = XCTestExpectation(description: "Multipart form data test")
169167
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/TestMultiPart")
170168

171-
let myStruct = MyStruct(name: "Bruce", lastName: "Wayne")
169+
let myStruct = MultiPartPostRequest(name: "Bruce", lastName: "Wayne")
172170
let multiPartRequest = HUMultiPartRequest(url: requestUrl!, method: .post, request: myStruct)
173171

174172
// ACT

HttpUtilityTests/TestModel/Response.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88

99
import Foundation
1010

11-
// MARK: - EmployeeResponse
12-
struct EmployeeResponse: Decodable {
13-
let id: Int?
14-
let name, role, joiningDate: String?
15-
let depID, salary: Int?
16-
let workPhone: String?
11+
// MARK: - AnimalResponse
12+
struct AnimalResponse: Decodable {
13+
let errorMessage: String?
14+
let data: [Animal]?
15+
}
1716

18-
enum CodingKeys: String, CodingKey {
19-
case id, name, role
20-
case joiningDate = "joining_date"
21-
case depID = "dep_id"
22-
case salary, workPhone
23-
}
17+
// MARK: - Datum
18+
struct Animal: Decodable {
19+
let name: String
20+
let image: String
2421
}
2522

2623
// MARK: - RegisterResponse

0 commit comments

Comments
 (0)