Skip to content

Commit b086b04

Browse files
committed
coverage
1 parent 6b115a5 commit b086b04

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

Sources/ParseSwift/Coding/AnyCodable.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ extension AnyCodable: Hashable {
7373
public func hash(into hasher: inout Hasher) {
7474
do {
7575
let encodedData = try ParseCoding.jsonEncoder().encode(self)
76-
guard let encodedString = String(data: encodedData, encoding: .utf8) else {
77-
hasher.combine(0)
78-
return
79-
}
76+
let encodedString = String(data: encodedData, encoding: .utf8)
8077
hasher.combine(encodedString)
8178
} catch {
8279
hasher.combine(0)

Sources/ParseSwift/Coding/AnyEncodable.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,7 @@ extension AnyEncodable: Hashable {
191191
public func hash(into hasher: inout Hasher) {
192192
do {
193193
let encodedData = try ParseCoding.jsonEncoder().encode(self)
194-
guard let encodedString = String(data: encodedData, encoding: .utf8) else {
195-
hasher.combine(0)
196-
return
197-
}
194+
let encodedString = String(data: encodedData, encoding: .utf8)
198195
hasher.combine(encodedString)
199196
} catch {
200197
hasher.combine(0)

Sources/ParseSwift/Types/ParseSchema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
use the master key in server-side applications where the key is kept secure and not
1515
exposed to the public.
1616
*/
17-
public struct ParseSchema<SchemaObject: ParseObject>: ParseType, Decodable {
17+
public struct ParseSchema<SchemaObject: ParseObject>: ParseType, Decodable, Equatable {
1818

1919
/// The class name of the `ParseSchema`.
2020
public var className: String

Tests/ParseSwiftTests/ParsePushPayloadAnyTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ class ParsePushPayloadAnyTests: XCTestCase {
157157
"ParsePushPayloadable ({\"alert\":{\"action\":\"to\",\"action-loc-key\":\"icon\",\"body\":\"pull up\",\"launch-image\":\"it\",\"loc-args\":[\"mother\"],\"loc-key\":\"cousin\",\"subtitle\":\"trip\",\"subtitle-loc-args\":[\"gone\"],\"subtitle-loc-key\":\"far\",\"title\":\"you\",\"title-loc-args\":[\"arg\"],\"title-loc-key\":\"it\"},\"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\"]})")
158158
let decoded2 = try ParseCoding.jsonDecoder().decode(ParsePushPayloadAny.self, from: encoded).convertToApple()
159159
XCTAssertEqual(decoded2, applePayload)
160+
var applePayload2 = applePayload
161+
applePayload2.sound = AnyCodable("wow")
162+
let encodedSound = try ParseCoding.parseEncoder().encode(applePayload2)
163+
let decodedSound = try ParseCoding.jsonDecoder().decode(ParsePushPayloadAny.self, from: encodedSound).convertToApple()
164+
XCTAssertEqual(decodedSound, applePayload2)
160165
}
161166

162167
func testConvertToFirebase() throws {

Tests/ParseSwiftTests/ParsePushPayloadAppleTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ParsePushPayloadAppleTests: XCTestCase {
7575
"ParsePushPayloadable ({\"push_type\":\"alert\",\"sound\":{\"critical\":true,\"name\":\"hello\",\"volume\":7}})")
7676
let soundObject: ParsePushAppleSound = try applePayload2.getSound()
7777
XCTAssertEqual(soundObject, sound)
78+
XCTAssertThrowsError(try applePayload2.getSound() as String)
7879
}
7980

8081
func testCoding() throws {
@@ -111,5 +112,18 @@ class ParsePushPayloadAppleTests: XCTestCase {
111112
XCTAssertEqual(applePayload, decoded)
112113
XCTAssertEqual(applePayload.description,
113114
"ParsePushPayloadable ({\"alert\":{\"action\":\"to\",\"action-loc-key\":\"icon\",\"body\":\"pull up\",\"launch-image\":\"it\",\"loc-args\":[\"mother\"],\"loc-key\":\"cousin\",\"subtitle\":\"trip\",\"subtitle-loc-args\":[\"gone\"],\"subtitle-loc-key\":\"far\",\"title\":\"you\",\"title-loc-args\":[\"arg\"],\"title-loc-key\":\"it\"},\"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\"]})")
115+
XCTAssertEqual(alert.description, "ParsePushAppleAlert ({\"action\":\"to\",\"action-loc-key\":\"icon\",\"body\":\"pull up\",\"launch-image\":\"it\",\"loc-args\":[\"mother\"],\"loc-key\":\"cousin\",\"subtitle\":\"trip\",\"subtitle-loc-args\":[\"gone\"],\"subtitle-loc-key\":\"far\",\"title\":\"you\",\"title-loc-args\":[\"arg\"],\"title-loc-key\":\"it\"})")
116+
let alert2 = ParsePushAppleAlert()
117+
XCTAssertNotEqual(alert, alert2)
118+
XCTAssertEqual(sound.description, "ParsePushAppleSound ({\"critical\":true,\"name\":\"hello\",\"volume\":7})")
119+
}
120+
121+
func testCodingAlert() throws {
122+
let body = "Hello from ParseSwift!"
123+
var applePayload = ParsePushPayloadApple(alert: .init(body: body))
124+
applePayload.body = "stop"
125+
let encoded = try ParseCoding.parseEncoder().encode(applePayload)
126+
let decoded = try ParseCoding.jsonDecoder().decode(ParsePushPayloadApple.self, from: encoded)
127+
XCTAssertEqual(applePayload, decoded)
114128
}
115129
}

Tests/ParseSwiftTests/ParsePushPayloadFirebaseTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ParsePushPayloadFirebaseTests: XCTestCase {
3939
func testInitializers() throws {
4040
let fcmPayload = ParsePushPayloadFirebase(notification: .init(body: "Bye FCM"))
4141
XCTAssertEqual(fcmPayload.description, "ParsePushPayloadable ({\"notification\":{\"body\":\"Bye FCM\"}})")
42+
let notification = ParsePushFirebaseNotification(title: "hello", body: "new", image: "world")
43+
XCTAssertEqual(notification.description, "ParsePushFirebaseNotification ({\"body\":\"new\",\"image\":\"world\",\"title\":\"hello\"})")
4244
}
4345

4446
func testCoding() throws {

0 commit comments

Comments
 (0)