-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSPErrorSpec.swift
148 lines (125 loc) · 5.96 KB
/
SPErrorSpec.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
//
// SPErrorSpec.swift
// ConsentViewController_ExampleTests
//
// Created by Vilas on 19/03/20.
// Copyright © 2020 CocoaPods. All rights reserved.
//
import Quick
import Nimble
@testable import ConsentViewController
func emptyRequest() -> URLRequest {
return URLRequest(url: URL(string: "/")!)
}
func aResponseWith(status: Int) -> HTTPURLResponse {
return HTTPURLResponse(url: URL(string: "/")!, statusCode: status, httpVersion: nil, headerFields: nil)!
}
// swiftlint:disable function_body_length
class SPErrorSpec: QuickSpec {
override func spec() {
describe("SPErrorSpec") {
describe("GenericNetworkError") {
context("when no response object is provided") {
it("has spCode: generic_network_request_999") {
let error = GenericNetworkError(request: emptyRequest(), response: nil)
expect(error.spCode).to(equal("sp_metric_generic_network_request_999"))
}
}
context("when we know the response status") {
it("has spCode: generic_network_request_{response.status}") {
let error = GenericNetworkError(request: emptyRequest(), response: aResponseWith(status: 500))
expect(error.spCode).to(equal("sp_metric_generic_network_request_500"))
}
}
}
describe("NoInternetConnection") {
it("has spCode: no_internet_connection") {
expect(NoInternetConnection().spCode).to(equal("sp_metric_no_internet_connection"))
}
}
describe("InternalServerError") {
it("has spCode: internal_server_error_{response.statusCode}") {
let error = InternalServerError(request: emptyRequest(), response: aResponseWith(status: 502))
expect(error.spCode).to(equal("sp_metric_internal_server_error_502"))
}
}
describe("ResourceNotFoundError") {
it("has spCode: resource_not_found_{response.statusCode}") {
let error = ResourceNotFoundError(request: emptyRequest(), response: aResponseWith(status: 404))
expect(error.spCode).to(equal("sp_metric_resource_not_found_404"))
}
}
describe("ConnectionTimeOutError") {
it("has spCode: connection_timeout") {
expect(ConnectionTimeOutError(url: nil, timeout: nil, campaignType: .unknown).spCode).to(equal("sp_metric_connection_timeout"))
}
}
describe("InvalidURLError") {
it("has spCode: invalid_url") {
expect(InvalidURLError(urlString: "").spCode).to(equal("sp_metric_invalid_url"))
}
}
describe("WebViewError") {
it("has spCode: web_view_error") {
expect(WebViewError().spCode).to(equal("sp_metric_web_view_error"))
}
}
describe("InvalidResponseWebMessageError") {
it("has spCode: invalid_response_web_message") {
expect(InvalidResponseWebMessageError().spCode).to(equal("sp_metric_invalid_response_web_message"))
}
}
describe("InvalidResponseNativeMessageError") {
it("has spCode: invalid_response_native_message") {
expect(InvalidResponseNativeMessageError().spCode).to(equal("sp_metric_invalid_response_native_message"))
}
}
describe("InvalidResponseConsentError") {
it("has spCode: invalid_response_consent") {
expect(InvalidResponseConsentError().spCode).to(equal("sp_metric_invalid_response_consent"))
}
}
describe("InvalidResponseCustomError") {
it("has spCode: invalid_response_custom_consent") {
expect(InvalidResponseCustomError().spCode).to(equal("sp_metric_invalid_response_custom_consent"))
}
}
describe("InvalidEventPayloadError") {
it("has spCode: invalid_event_payload") {
expect(InvalidEventPayloadError().spCode).to(equal("sp_metric_invalid_event_payload"))
}
}
describe("InvalidOnActionEventPayloadError") {
it("has spCode: invalid_event_payload") {
expect(InvalidOnActionEventPayloadError().spCode).to(equal("sp_metric_invalid_onAction_event_payload"))
}
}
describe("RenderingAppError") {
describe("if not code is provided") {
it("its spCode should be rendering_app_error") {
expect(RenderingAppError(nil).spCode).to(equal("sp_metric_rendering_app_error"))
}
}
describe("if a code is provided") {
it("its spCode should be the same as the code provided") {
expect(RenderingAppError("foo").spCode).to(equal("foo"))
}
}
}
describe("InvalidRequestError") {
it("has spCode: invalid_request_error") {
expect(InvalidRequestError().spCode).to(equal("sp_metric_invalid_request_error"))
}
}
describe("UnableToLoadJSReceiver") {
it("has spCode: unable_to_load_jsreceiver") {
expect(UnableToLoadJSReceiver().spCode).to(equal("sp_metric_unable_to_load_jsreceiver"))
}
}
it("Test InvalidArgumentError method") {
let errorObject = InvalidArgumentError(message: "The operation couldn't be completed")
expect(errorObject.description).to(equal("The operation couldn't be completed"))
}
}
}
}