Skip to content

Commit

Permalink
Updated unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
francodriansetti committed Mar 1, 2024
1 parent 42f298e commit 82d6ccb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
12 changes: 12 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/PlaybackSDKTests.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<EnvironmentVariables>
<EnvironmentVariable
key = "API_KEY"
value = "f3Beljhmlz2ea7M9TfErE6mKPsAcY3BrasMMEG24"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "ENTRY_ID"
value = "0_k3mz0mf8"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
39 changes: 0 additions & 39 deletions Tests/PlaybackSDKTests/MockPlayerInformationAPI.swift

This file was deleted.

42 changes: 38 additions & 4 deletions Tests/PlaybackSDKTests/PlayBackSDKManagerTests.swift.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PlayBackSDKManagerTests.swift.swift
//
//
//
// Created by Franco Driansetti on 29/02/2024.
//
Expand All @@ -14,12 +14,17 @@ class PlayBackSDKManagerTests: XCTestCase {
var cancellables = Set<AnyCancellable>()
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 {
Expand All @@ -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)")
Expand All @@ -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")

Expand All @@ -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)
}
}

0 comments on commit 82d6ccb

Please sign in to comment.