-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
Tests/AppcuesKitTests/Actions/AppcuesRequestPushActionTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// AppcuesRequestPushActionTests.swift | ||
// AppcuesKitTests | ||
// | ||
// Created by Matt on 2024-02-27. | ||
// Copyright © 2024 Appcues. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import AppcuesKit | ||
|
||
@available(iOS 13.0, *) | ||
class AppcuesRequestPushActionTests: XCTestCase { | ||
|
||
var appcues: MockAppcues! | ||
|
||
override func setUpWithError() throws { | ||
appcues = MockAppcues() | ||
} | ||
|
||
func testInit() throws { | ||
// Act | ||
let action = AppcuesRequestPushAction(configuration: AppcuesExperiencePluginConfiguration(nil, appcues: appcues)) | ||
|
||
// Assert | ||
XCTAssertEqual(AppcuesRequestPushAction.type, "@appcues/request-push") | ||
XCTAssertNotNil(action) | ||
} | ||
|
||
func testExecute() throws { | ||
// Arrange | ||
var eventCount = 0 | ||
var completionCount = 0 | ||
let action = AppcuesRequestPushAction(appcues: appcues) | ||
|
||
appcues.analyticsPublisher.onPublish = { update in | ||
XCTAssertEqual(update.type, .event(name: Events.Device.deviceUpdated.rawValue, interactive: false)) | ||
eventCount += 1 | ||
} | ||
|
||
// Act | ||
action?.execute(completion: { completionCount += 1 }) | ||
|
||
// Assert | ||
XCTAssertEqual(eventCount, 1) | ||
XCTAssertEqual(completionCount, 1) | ||
} | ||
|
||
func testExecuteCompletesWithoutAppcuesInstance() throws { | ||
// Arrange | ||
var completionCount = 0 | ||
let action = try XCTUnwrap(AppcuesRequestPushAction(appcues: nil)) | ||
|
||
// Act | ||
action.execute(completion: { completionCount += 1 }) | ||
|
||
// Assert | ||
XCTAssertEqual(completionCount, 1) | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
extension AppcuesRequestPushAction { | ||
convenience init?(appcues: Appcues?) { | ||
self.init(configuration: AppcuesExperiencePluginConfiguration(nil, appcues: appcues)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters