From 82d6ccb70baa7a155b2ba1fde193c526be2fa860 Mon Sep 17 00:00:00 2001
From: Franco Driansetti <7194678+francodriansetti@users.noreply.github.com>
Date: Fri, 1 Mar 2024 13:13:53 +0100
Subject: [PATCH] Updated unit test
---
.../xcschemes/PlaybackSDKTests.xcscheme | 12 ++++++
.../MockPlayerInformationAPI.swift | 39 -----------------
.../PlayBackSDKManagerTests.swift.swift | 42 +++++++++++++++++--
3 files changed, 50 insertions(+), 43 deletions(-)
delete mode 100644 Tests/PlaybackSDKTests/MockPlayerInformationAPI.swift
diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme
index 3917f0a..ac94277 100644
--- a/.swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme
+++ b/.swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme
@@ -35,6 +35,18 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
+
+
+
+
+
+
AnyPublisher {
- let mockResponse = PlayerInformationResponseModel(
- player: PlayerInfo(
- bitmovin: Bitmovin(
- license: "12345678-1111-1111-1111-123456789012",
- integrations: Integrations(
- mux: Mux(
- playerName: "some name",
- envKey: "env_key_123"
- ),
- resume: Resume(
- enabled: true
- )
- )
- )
- ),
- defaults: Defaults(
- player: "bitmovin"
- )
- )
- return Just(mockResponse)
- .setFailureType(to: Error.self)
- .eraseToAnyPublisher()
- }
-}
-
diff --git a/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift b/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift
index e97ce24..66eca6b 100644
--- a/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift
+++ b/Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift
@@ -1,6 +1,6 @@
//
// PlayBackSDKManagerTests.swift.swift
-//
+//
//
// Created by Franco Driansetti on 29/02/2024.
//
@@ -14,12 +14,17 @@ class PlayBackSDKManagerTests: XCTestCase {
var cancellables = Set()
var manager: PlayBackSDKManager!
var apiKey: String!
-
+ var baseURL: String!
+ var entryID: String!
+
override func setUpWithError() throws {
try super.setUpWithError()
manager = PlayBackSDKManager()
apiKey = ProcessInfo.processInfo.environment["API_KEY"]
XCTAssertNotNil(apiKey, "API key should be provided via environment variable")
+ entryID = ProcessInfo.processInfo.environment["ENTRY_ID"]
+ XCTAssertNotNil(entryID, "API key should be provided via environment variable")
+
}
override func tearDownWithError() throws {
@@ -40,7 +45,6 @@ class PlayBackSDKManagerTests: XCTestCase {
case .success(let license):
XCTAssertNotNil(license, "Bitmovin license should not be nil")
XCTAssertFalse(license.isEmpty, "Bitmovin license should not be empty")
- XCTAssertEqual(license, "12345678-1111-1111-1111-123456789012", "Expected Bitmovin license not received")
expectation.fulfill()
case .failure(let error):
XCTFail("Initialization failed with error: \(error.localizedDescription)")
@@ -49,7 +53,33 @@ class PlayBackSDKManagerTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}
+
+ func testLoadHLSStream() {
+ let initializationExpectation = expectation(description: "SDK initialization")
+ manager.initialize(apiKey: apiKey, baseURL: baseURL) { result in
+ switch result {
+ case .success:
+ initializationExpectation.fulfill()
+ case .failure(let error):
+ XCTFail("SDK initialization failed with error: \(error.localizedDescription)")
+ }
+ }
+ waitForExpectations(timeout: 5, handler: nil)
+ let hlsExpectation = expectation(description: "HLS stream loading expectation")
+ manager.loadHLSStream(forEntryId: entryID, andAuthorizationToken: nil) { result in
+ switch result {
+ case .success(let hlsURL):
+ XCTAssertNotNil(hlsURL, "HLS stream URL should not be nil")
+ hlsExpectation.fulfill()
+ case .failure(let error):
+ XCTFail("Loading HLS stream failed with error: \(error.localizedDescription)")
+ }
+ }
+
+ waitForExpectations(timeout: 5, handler: nil)
+ }
+
func testInitializeWithEmptyAPIKey() {
let expectation = expectation(description: "Initialization expectation")
@@ -66,5 +96,9 @@ class PlayBackSDKManagerTests: XCTestCase {
waitForExpectations(timeout: 5, handler: nil)
}
- // Add more tests for other functionalities as needed
+ func testLoadPlayer() {
+ let playerView = manager.loadPlayer(entryID: "exampleEntryID", authorizationToken: "exampleToken", onError: nil)
+ // Assert that playerView is not nil or do further UI testing if possible
+ XCTAssertNotNil(playerView)
+ }
}