|
| 1 | +// |
| 2 | +// ParsePushPayloadFirebaseTests.swift |
| 3 | +// ParseSwift |
| 4 | +// |
| 5 | +// Created by Corey Baker on 6/12/22. |
| 6 | +// Copyright © 2022 Parse Community. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import Foundation |
| 10 | +import XCTest |
| 11 | +@testable import ParseSwift |
| 12 | + |
| 13 | +// swiftlint:disable line_length |
| 14 | + |
| 15 | +class ParsePushPayloadFirebaseTests: XCTestCase { |
| 16 | + |
| 17 | + override func setUpWithError() throws { |
| 18 | + try super.setUpWithError() |
| 19 | + guard let url = URL(string: "http://localhost:1337/1") else { |
| 20 | + XCTFail("Should create valid URL") |
| 21 | + return |
| 22 | + } |
| 23 | + ParseSwift.initialize(applicationId: "applicationId", |
| 24 | + clientKey: "clientKey", |
| 25 | + masterKey: "masterKey", |
| 26 | + serverURL: url, |
| 27 | + testing: true) |
| 28 | + } |
| 29 | + |
| 30 | + override func tearDownWithError() throws { |
| 31 | + try super.tearDownWithError() |
| 32 | + MockURLProtocol.removeAll() |
| 33 | + #if !os(Linux) && !os(Android) && !os(Windows) |
| 34 | + try KeychainStore.shared.deleteAll() |
| 35 | + #endif |
| 36 | + try ParseStorage.shared.deleteAll() |
| 37 | + } |
| 38 | + |
| 39 | + func testInitializers() throws { |
| 40 | + let fcmPayload = ParsePushPayloadFirebase(notification: .init(body: "Bye FCM")) |
| 41 | + XCTAssertEqual(fcmPayload.description, "ParsePushPayloadable ({\"notification\":{\"body\":\"Bye FCM\"}})") |
| 42 | + } |
| 43 | + |
| 44 | + func testCoding() throws { |
| 45 | + var notification = ParsePushFirebaseNotification(title: "hello", body: "android", icon: "world") |
| 46 | + notification.sound = "yes" |
| 47 | + notification.badge = "no" |
| 48 | + notification.androidChannelId = "you" |
| 49 | + notification.bodyLocArgs = ["mother"] |
| 50 | + notification.bodyLocKey = "cousin" |
| 51 | + notification.clickAction = "to" |
| 52 | + notification.image = "icon" |
| 53 | + notification.subtitle = "trip" |
| 54 | + notification.tag = "it" |
| 55 | + notification.color = "blue" |
| 56 | + notification.titleLocArgs = ["arg"] |
| 57 | + notification.titleLocKey = "it" |
| 58 | + var fcmPayload = ParsePushPayloadFirebase(notification: notification) |
| 59 | + fcmPayload.data = ["help": "you"] |
| 60 | + fcmPayload.priority = .high |
| 61 | + fcmPayload.contentAvailable = true |
| 62 | + fcmPayload.mutableContent = true |
| 63 | + fcmPayload.collapseKey = "nope" |
| 64 | + fcmPayload.delayWhileIdle = false |
| 65 | + fcmPayload.dryRun = false |
| 66 | + fcmPayload.title = "peace" |
| 67 | + fcmPayload.restrictedPackageName = "geez" |
| 68 | + fcmPayload.uri = URL(string: "https://parse.org") |
| 69 | + let encoded = try ParseCoding.parseEncoder().encode(fcmPayload) |
| 70 | + let decoded = try ParseCoding.jsonDecoder().decode(ParsePushPayloadFirebase.self, from: encoded) |
| 71 | + XCTAssertEqual(fcmPayload, decoded) |
| 72 | + XCTAssertEqual(fcmPayload.description, |
| 73 | + "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\"})") |
| 74 | + } |
| 75 | +} |
0 commit comments