Skip to content

Commit 98f454d

Browse files
committed
adding integration tests
1 parent 8a01e15 commit 98f454d

File tree

4 files changed

+144
-3
lines changed

4 files changed

+144
-3
lines changed

HttpUtility.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
8656BC582483E3C60023549D /* EncodableExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8656BC572483E3C60023549D /* EncodableExtension.swift */; };
1111
8656BC5B2483E43D0023549D /* EncodableExtensionUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8656BC5A2483E43D0023549D /* EncodableExtensionUnitTest.swift */; };
12+
8656BC5E2484313F0023549D /* HttpUtilityIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8656BC5D2484313F0023549D /* HttpUtilityIntegrationTests.swift */; };
13+
8656BC61248495700023549D /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8656BC60248495700023549D /* Response.swift */; };
1214
86719EA024720BD1002A2AB0 /* HttpUtility.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86719E9624720BD1002A2AB0 /* HttpUtility.framework */; };
1315
86719EA524720BD1002A2AB0 /* HttpUtilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86719EA424720BD1002A2AB0 /* HttpUtilityTests.swift */; };
1416
86719EA724720BD1002A2AB0 /* HttpUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 86719E9924720BD1002A2AB0 /* HttpUtility.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -28,6 +30,8 @@
2830
/* Begin PBXFileReference section */
2931
8656BC572483E3C60023549D /* EncodableExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableExtension.swift; sourceTree = "<group>"; };
3032
8656BC5A2483E43D0023549D /* EncodableExtensionUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableExtensionUnitTest.swift; sourceTree = "<group>"; };
33+
8656BC5D2484313F0023549D /* HttpUtilityIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpUtilityIntegrationTests.swift; sourceTree = "<group>"; };
34+
8656BC60248495700023549D /* Response.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = "<group>"; };
3135
86719E9624720BD1002A2AB0 /* HttpUtility.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HttpUtility.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3236
86719E9924720BD1002A2AB0 /* HttpUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HttpUtility.h; sourceTree = "<group>"; };
3337
86719E9A24720BD1002A2AB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -72,6 +76,22 @@
7276
path = ExtensionsTests;
7377
sourceTree = "<group>";
7478
};
79+
8656BC5C248431200023549D /* IntegrationTests */ = {
80+
isa = PBXGroup;
81+
children = (
82+
8656BC5D2484313F0023549D /* HttpUtilityIntegrationTests.swift */,
83+
);
84+
path = IntegrationTests;
85+
sourceTree = "<group>";
86+
};
87+
8656BC5F248495620023549D /* TestModel */ = {
88+
isa = PBXGroup;
89+
children = (
90+
8656BC60248495700023549D /* Response.swift */,
91+
);
92+
path = TestModel;
93+
sourceTree = "<group>";
94+
};
7595
86719E8C24720BD1002A2AB0 = {
7696
isa = PBXGroup;
7797
children = (
@@ -104,6 +124,8 @@
104124
86719EA324720BD1002A2AB0 /* HttpUtilityTests */ = {
105125
isa = PBXGroup;
106126
children = (
127+
8656BC5F248495620023549D /* TestModel */,
128+
8656BC5C248431200023549D /* IntegrationTests */,
107129
8656BC592483E4200023549D /* ExtensionsTests */,
108130
86719EA424720BD1002A2AB0 /* HttpUtilityTests.swift */,
109131
86719EA624720BD1002A2AB0 /* Info.plist */,
@@ -230,8 +252,10 @@
230252
isa = PBXSourcesBuildPhase;
231253
buildActionMask = 2147483647;
232254
files = (
255+
8656BC61248495700023549D /* Response.swift in Sources */,
233256
8656BC5B2483E43D0023549D /* EncodableExtensionUnitTest.swift in Sources */,
234257
86719EA524720BD1002A2AB0 /* HttpUtilityTests.swift in Sources */,
258+
8656BC5E2484313F0023549D /* HttpUtilityIntegrationTests.swift in Sources */,
235259
);
236260
runOnlyForDeploymentPostprocessing = 0;
237261
};

HttpUtility/HttpUtility.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ struct HttpUtility
3636
_=completionHandler(result)
3737
}
3838
catch let error{
39-
debugPrint("error occured while decoding = \(error.localizedDescription)")
39+
debugPrint("error occured while decoding = \(error)")
4040
}
41+
}else{
42+
_=completionHandler(nil) //todo: you need to send error that you receive from server
4143
}
42-
_=completionHandler(nil) //todo: you need to send error that you receive from server
4344

4445
}.resume()
4546
}
@@ -64,8 +65,10 @@ struct HttpUtility
6465
catch let decodingError {
6566
debugPrint(decodingError)
6667
}
68+
}else{
69+
_=completionHandler(nil) //todo: you need to send error that you receive from server
6770
}
68-
_=completionHandler(nil) //todo: you need to send error that you receive from server
71+
6972

7073
}.resume()
7174
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// HttpUtilityIntegrationTests.swift
3+
// HttpUtilityTests
4+
//
5+
// Created by CodeCat15 on 5/31/20.
6+
// Copyright © 2020 CodeCat15. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import HttpUtility
11+
12+
class HttpUtilityIntegrationTests: XCTestCase {
13+
14+
private typealias Employees = [EmployeeResponse]
15+
private let _utility = HttpUtility()
16+
17+
override func setUpWithError() throws {
18+
// Put setup code here. This method is called before the invocation of each test method in the class.
19+
}
20+
21+
override func tearDownWithError() throws {
22+
// Put teardown code here. This method is called after the invocation of each test method in the class.
23+
}
24+
25+
func test_getApiData_With_Valid_Request_Returns_Success()
26+
{
27+
// ARRANGE
28+
let requestUrl = URL(string: "http://demo0333988.mockable.io/Employees")
29+
let expectation = XCTestExpectation(description: "Data received from server")
30+
31+
// ACT
32+
_utility.getApiData(requestUrl: requestUrl!, resultType: Employees.self) { (response) in
33+
34+
// ASSERT
35+
XCTAssertNotNil(response)
36+
XCTAssertTrue(response?.count == 2)
37+
expectation.fulfill()
38+
}
39+
40+
wait(for: [expectation], timeout: 10.0)
41+
}
42+
43+
func test_postApiData_With_Valid_Request_Returns_Success()
44+
{
45+
// ARRANGE
46+
let requestUrl = URL(string: "https://api-dev-scus-demo.azurewebsites.net/api/User/RegisterUser")
47+
let registerUserRequest = RegisterUserRequest(firstName: "code", lastName: "cat15", email: "[email protected]", password: "1234")
48+
let registerUserBody = try! JSONEncoder().encode(registerUserRequest)
49+
let expectation = XCTestExpectation(description: "Data received from server")
50+
// ACT
51+
_utility.postApiData(requestUrl: requestUrl!, requestBody: registerUserBody, resultType: RegisterResponse.self) { (response) in
52+
XCTAssertNotNil(response)
53+
expectation.fulfill()
54+
}
55+
56+
wait(for: [expectation], timeout: 10.0)
57+
}
58+
59+
func testPerformanceExample() throws {
60+
// This is an example of a performance test case.
61+
self.measure {
62+
// Put the code you want to measure the time of here.
63+
}
64+
}
65+
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// EmployeeResponse.swift
3+
// HttpUtilityTests
4+
//
5+
// Created by CodeCat15 on 5/31/20.
6+
// Copyright © 2020 CodeCat15. All rights reserved.
7+
//
8+
9+
import Foundation
10+
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?
17+
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+
}
24+
}
25+
26+
// MARK: - RegisterUserRequest
27+
struct RegisterUserRequest: Encodable
28+
{
29+
let firstName, lastName, email, password: String
30+
31+
enum CodingKeys: String, CodingKey {
32+
case firstName = "First_Name"
33+
case lastName = "Last_Name"
34+
case email = "Email"
35+
case password = "Password"
36+
}
37+
}
38+
39+
// MARK: - RegisterResponse
40+
struct RegisterResponse: Codable {
41+
let errorMessage: String?
42+
let data: EmployeeRegisterResponse?
43+
}
44+
45+
// MARK: - EmployeeRegisterResponse
46+
struct EmployeeRegisterResponse: Codable {
47+
let name, email, id, joining: String?
48+
}

0 commit comments

Comments
 (0)