Skip to content

Commit f0469e0

Browse files
committed
more coverage
1 parent b086b04 commit f0469e0

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

Sources/ParseSwift/Coding/AnyDecodable.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ extension AnyDecodable: Equatable {
112112
return lhs == rhs
113113
case let (lhs as [AnyDecodable], rhs as [AnyDecodable]):
114114
return lhs == rhs
115-
case let (lhs as AnyEncodable, rhs as AnyEncodable):
116-
return lhs == rhs
117115
default:
118116
return false
119117
}

Sources/ParseSwift/Types/Query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ enum RawCodingKey: CodingKey {
14371437
}
14381438
}
14391439
var intValue: Int? {
1440-
Int(stringValue)
1440+
nil
14411441
}
14421442
init?(stringValue: String) {
14431443
self = .key(stringValue)

Tests/ParseSwiftTests/ParsePushPayloadAnyTests.swift

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,40 @@ class ParsePushPayloadAnyTests: XCTestCase {
111111
let encoded2 = try ParseCoding.parseEncoder().encode(fcmPayload)
112112
let decoded2 = try ParseCoding.jsonDecoder().decode(ParsePushPayloadFirebase.self, from: encoded2)
113113
XCTAssertEqual(fcmPayload, decoded2)
114-
XCTAssertEqual(fcmPayload.description,
115-
"ParsePushPayloadable ({\"collapseKey\":\"nope\",\"data\":{\"help\":\"you\"},\"delayWhileIdle\":false,\"dryRun\":false,\"notification\":{\"android_channel_id\":\"you\",\"badge\":\"no\",\"body\":\"android\",\"body_loc-key\":\"cousin\",\"body-loc-args\":[\"mother\"],\"click_action\":\"to\",\"color\":\"blue\",\"icon\":\"world\",\"image\":\"icon\",\"sound\":\"yes\",\"subtitle\":\"trip\",\"tag\":\"it\",\"title\":\"hello\",\"title_loc_args\":[\"arg\"],\"title_loc_key\":\"it\"},\"restrictedPackageName\":\"geez\",\"title\":\"peace\",\"uri\":\"https:\\/\\/parse.org\"})")
116114
let decodedAny2 = try ParseCoding.jsonDecoder().decode(ParsePushPayloadAny.self, from: encoded).convertToApple()
117115
XCTAssertEqual(decodedAny2, applePayload)
116+
#if !os(Linux) && !os(Android) && !os(Windows)
117+
XCTAssertEqual(fcmPayload.description,
118+
"ParsePushPayloadable ({\"collapseKey\":\"nope\",\"data\":{\"help\":\"you\"},\"delayWhileIdle\":false,\"dryRun\":false,\"notification\":{\"android_channel_id\":\"you\",\"badge\":\"no\",\"body\":\"android\",\"body_loc-key\":\"cousin\",\"body-loc-args\":[\"mother\"],\"click_action\":\"to\",\"color\":\"blue\",\"icon\":\"world\",\"image\":\"icon\",\"sound\":\"yes\",\"subtitle\":\"trip\",\"tag\":\"it\",\"title\":\"hello\",\"title_loc_args\":[\"arg\"],\"title_loc_key\":\"it\"},\"restrictedPackageName\":\"geez\",\"title\":\"peace\",\"uri\":\"https:\\/\\/parse.org\"})")
119+
#endif
120+
}
121+
122+
func testAppleAlertStringDecode() throws {
123+
let sound = ParsePushAppleSound(critical: true, name: "hello", volume: 7)
124+
let alert = ParsePushAppleAlert(body: "pull up")
125+
var anyPayload = ParsePushPayloadAny()
126+
anyPayload.alert = alert
127+
anyPayload.badge = AnyCodable(1)
128+
anyPayload.sound = AnyCodable(sound)
129+
anyPayload.urlArgs = ["help"]
130+
anyPayload.interruptionLevel = "yolo"
131+
anyPayload.topic = "naw"
132+
anyPayload.threadId = "yep"
133+
anyPayload.collapseId = "nope"
134+
anyPayload.pushType = .background
135+
anyPayload.targetContentId = "press"
136+
anyPayload.relevanceScore = 2.0
137+
anyPayload.priority = 6
138+
anyPayload.contentAvailable = 1
139+
anyPayload.mutableContent = 1
140+
141+
let applePayload = anyPayload.convertToApple()
142+
guard let jsonData = "{\"alert\":\"pull up\",\"badge\":1,\"collapse_id\":\"nope\",\"content-available\":1,\"interruptionLevel\":\"yolo\",\"mutable-content\":1,\"priority\":6,\"push_type\":\"background\",\"relevance-score\":2,\"sound\":{\"critical\":true,\"name\":\"hello\",\"volume\":7},\"targetContentIdentifier\":\"press\",\"threadId\":\"yep\",\"topic\":\"naw\",\"urlArgs\":[\"help\"]}".data(using: .utf8) else {
143+
XCTFail("Should have unwrapped")
144+
return
145+
}
146+
let decodedAlert = try ParseCoding.jsonDecoder().decode(ParsePushPayloadAny.self, from: jsonData).convertToApple()
147+
XCTAssertEqual(decodedAlert, applePayload)
118148
}
119149

120150
func testConvertToApple() throws {
@@ -196,9 +226,11 @@ class ParsePushPayloadAnyTests: XCTestCase {
196226
let encoded = try ParseCoding.parseEncoder().encode(fcmPayload)
197227
let decoded = try ParseCoding.jsonDecoder().decode(ParsePushPayloadFirebase.self, from: encoded)
198228
XCTAssertEqual(fcmPayload, decoded)
199-
XCTAssertEqual(fcmPayload.description,
200-
"ParsePushPayloadable ({\"collapseKey\":\"nope\",\"contentAvailable\":true,\"data\":{\"help\":\"you\"},\"delayWhileIdle\":false,\"dryRun\":false,\"mutableContent\":true,\"notification\":{\"android_channel_id\":\"you\",\"badge\":\"no\",\"body\":\"android\",\"body_loc-key\":\"cousin\",\"body-loc-args\":[\"mother\"],\"click_action\":\"to\",\"color\":\"blue\",\"icon\":\"world\",\"image\":\"icon\",\"sound\":\"yes\",\"subtitle\":\"trip\",\"tag\":\"it\",\"title\":\"hello\",\"title_loc_args\":[\"arg\"],\"title_loc_key\":\"it\"},\"priority\":\"high\",\"restrictedPackageName\":\"geez\",\"title\":\"peace\",\"uri\":\"https:\\/\\/parse.org\"})")
201229
let decoded2 = try ParseCoding.jsonDecoder().decode(ParsePushPayloadAny.self, from: encoded).convertToFirebase()
202230
XCTAssertEqual(decoded2, fcmPayload)
231+
#if !os(Linux) && !os(Android) && !os(Windows)
232+
XCTAssertEqual(fcmPayload.description,
233+
"ParsePushPayloadable ({\"collapseKey\":\"nope\",\"contentAvailable\":true,\"data\":{\"help\":\"you\"},\"delayWhileIdle\":false,\"dryRun\":false,\"mutableContent\":true,\"notification\":{\"android_channel_id\":\"you\",\"badge\":\"no\",\"body\":\"android\",\"body_loc-key\":\"cousin\",\"body-loc-args\":[\"mother\"],\"click_action\":\"to\",\"color\":\"blue\",\"icon\":\"world\",\"image\":\"icon\",\"sound\":\"yes\",\"subtitle\":\"trip\",\"tag\":\"it\",\"title\":\"hello\",\"title_loc_args\":[\"arg\"],\"title_loc_key\":\"it\"},\"priority\":\"high\",\"restrictedPackageName\":\"geez\",\"title\":\"peace\",\"uri\":\"https:\\/\\/parse.org\"})")
234+
#endif
203235
}
204236
}

Tests/ParseSwiftTests/ParsePushPayloadAppleTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,35 @@ class ParsePushPayloadAppleTests: XCTestCase {
125125
let encoded = try ParseCoding.parseEncoder().encode(applePayload)
126126
let decoded = try ParseCoding.jsonDecoder().decode(ParsePushPayloadApple.self, from: encoded)
127127
XCTAssertEqual(applePayload, decoded)
128+
let anyEncodablePayload = AnyEncodable(applePayload)
129+
let anyEncodablePayload2 = AnyEncodable(decoded)
130+
XCTAssertEqual(anyEncodablePayload, anyEncodablePayload2)
131+
}
132+
133+
func testAppleAlertStringDecode() throws {
134+
let sound = ParsePushAppleSound(critical: true, name: "hello", volume: 7)
135+
let alert = ParsePushAppleAlert(body: "pull up")
136+
var applePayload = ParsePushPayloadApple()
137+
applePayload.alert = alert
138+
applePayload.badge = AnyCodable(1)
139+
applePayload.sound = AnyCodable(sound)
140+
applePayload.urlArgs = ["help"]
141+
applePayload.interruptionLevel = "yolo"
142+
applePayload.topic = "naw"
143+
applePayload.threadId = "yep"
144+
applePayload.collapseId = "nope"
145+
applePayload.pushType = .background
146+
applePayload.targetContentId = "press"
147+
applePayload.relevanceScore = 2.0
148+
applePayload.priority = 6
149+
applePayload.contentAvailable = 1
150+
applePayload.mutableContent = 1
151+
152+
guard let jsonData = "{\"alert\":\"pull up\",\"badge\":1,\"collapse_id\":\"nope\",\"content-available\":1,\"interruptionLevel\":\"yolo\",\"mutable-content\":1,\"priority\":6,\"push_type\":\"background\",\"relevance-score\":2,\"sound\":{\"critical\":true,\"name\":\"hello\",\"volume\":7},\"targetContentIdentifier\":\"press\",\"threadId\":\"yep\",\"topic\":\"naw\",\"urlArgs\":[\"help\"]}".data(using: .utf8) else {
153+
XCTFail("Should have unwrapped")
154+
return
155+
}
156+
let decodedAlert = try ParseCoding.jsonDecoder().decode(ParsePushPayloadApple.self, from: jsonData)
157+
XCTAssertEqual(decodedAlert, applePayload)
128158
}
129159
}

Tests/ParseSwiftTests/ParsePushPayloadFirebaseTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class ParsePushPayloadFirebaseTests: XCTestCase {
7171
let encoded = try ParseCoding.parseEncoder().encode(fcmPayload)
7272
let decoded = try ParseCoding.jsonDecoder().decode(ParsePushPayloadFirebase.self, from: encoded)
7373
XCTAssertEqual(fcmPayload, decoded)
74+
#if !os(Linux) && !os(Android) && !os(Windows)
7475
XCTAssertEqual(fcmPayload.description,
7576
"ParsePushPayloadable ({\"collapseKey\":\"nope\",\"contentAvailable\":true,\"data\":{\"help\":\"you\"},\"delayWhileIdle\":false,\"dryRun\":false,\"mutableContent\":true,\"notification\":{\"android_channel_id\":\"you\",\"badge\":\"no\",\"body\":\"android\",\"body_loc-key\":\"cousin\",\"body-loc-args\":[\"mother\"],\"click_action\":\"to\",\"color\":\"blue\",\"icon\":\"world\",\"image\":\"icon\",\"sound\":\"yes\",\"subtitle\":\"trip\",\"tag\":\"it\",\"title\":\"hello\",\"title_loc_args\":[\"arg\"],\"title_loc_key\":\"it\"},\"priority\":\"high\",\"restrictedPackageName\":\"geez\",\"title\":\"peace\",\"uri\":\"https:\\/\\/parse.org\"})")
77+
#endif
7678
}
7779
}

0 commit comments

Comments
 (0)