Skip to content

Commit bfd2ba6

Browse files
committed
[NetLens] - prepare networkCall factory class in order to mock success and failed calls
1 parent 6f57579 commit bfd2ba6

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// NetworkCall.swift
3+
// NetLens
4+
//
5+
// Created by NetLens on 25/06/2025.
6+
//
7+
8+
@testable import NetLens
9+
10+
import Foundation
11+
12+
class NetworkCallFactory {
13+
14+
static func makeSuccessCall(
15+
url: String = "https://www.api.test.com/success",
16+
method: HTTPMethod = .GET
17+
) -> NetworkCall {
18+
NetworkCall(
19+
url: URL(string: url)!,
20+
method: method,
21+
statusCode: 200,
22+
timeStamp: Date(),
23+
duration: .milliseconds(500)
24+
)
25+
}
26+
27+
static func makeFailedCall(
28+
url: String = "https://www.api.test.com/success",
29+
method: HTTPMethod = .GET,
30+
statusCode: Int = 400
31+
) -> NetworkCall {
32+
NetworkCall(
33+
url: URL(string: url)!,
34+
method: method,
35+
statusCode: statusCode,
36+
timeStamp: Date(),
37+
duration: .seconds(1),
38+
error: NetworkError(
39+
code: statusCode,
40+
message: "Not Found"
41+
)
42+
)
43+
}
44+
}
45+

0 commit comments

Comments
 (0)