Skip to content

Commit

Permalink
Merge branch 'feature/playlist_unit-test-cases' into feature/CORE-459…
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Russello committed Oct 28, 2024
2 parents 349ce61 + c177c24 commit 0b6e45b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/PlaybackSDK/PlaybackSDKManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public class PlaybackSDKManager {
completion(.failure(.networkError(error)))
}
case .success(let details):
// Call the completion handler with the HLS stream URL
// Call the completion handler with the video details
completion(.success(details))
}
})
Expand Down
69 changes: 66 additions & 3 deletions Tests/PlaybackSDKTests/PlaybackSDKManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PlaybackSDKManagerTests: XCTestCase {
var manager: PlaybackSDKManager!
var apiKey: String!
var entryID: String!
var playlistEntryID: [String]!

override func setUpWithError() throws {
try super.setUpWithError()
Expand All @@ -23,6 +24,7 @@ class PlaybackSDKManagerTests: XCTestCase {
XCTAssertNotNil(apiKey, "API key should be provided via environment variable")
entryID = TestConfig.testEntryID
XCTAssertNotNil(entryID, "Entry ID should be provided via environment variable")
playlistEntryID = TestConfig.testPlaylistEntryID
}

override func tearDownWithError() throws {
Expand Down Expand Up @@ -68,6 +70,61 @@ class PlaybackSDKManagerTests: XCTestCase {

waitForExpectations(timeout: 5, handler: nil)
}

func testLoadAllHLSStreams() {
let initializationExpectation = expectation(description: "SDK initialization")
manager.initialize(apiKey: apiKey) { 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 videoDetailsExpectation = expectation(description: "Video details loading expectation")
manager.loadAllHLSStream(forEntryIds: playlistEntryID, andAuthorizationToken: nil) { result in
switch result {
case .success(let videoDetails):
XCTAssertNotNil(videoDetails.0, "Video details should not be nil")
XCTAssertTrue(videoDetails.1.isEmpty, "Playlist errors should be void")
videoDetailsExpectation.fulfill()
case .failure(let error):
XCTFail("Loading Playlist video details failed with error: \(error.localizedDescription)")
}
}
waitForExpectations(timeout: 5, handler: nil)
}

func testLoadAllHLSStreamsWithError() {
let initializationExpectation = expectation(description: "SDK initialization")
manager.initialize(apiKey: apiKey) { 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 videoDetailsExpectation = expectation(description: "Video details loading expectation")
var playlistEntryIDwithError: [String] = playlistEntryID
// Adding a fake entryId to check that the error callback works
playlistEntryIDwithError.append("0_xxxxxxxx")
manager.loadAllHLSStream(forEntryIds: playlistEntryIDwithError, andAuthorizationToken: nil) { result in
switch result {
case .success(let videoDetails):
XCTAssertNotNil(videoDetails.0, "Video details should not be nil")
XCTAssertTrue(videoDetails.1.isEmpty == false, "Playlist errors should be not empty")
videoDetailsExpectation.fulfill()
case .failure(let error):
XCTFail("Loading Playlist video details failed with error: \(error.localizedDescription)")
}
}
waitForExpectations(timeout: 5, handler: nil)
}

func testLoadHLSStream() {
let initializationExpectation = expectation(description: "SDK initialization")
Expand All @@ -84,8 +141,8 @@ class PlaybackSDKManagerTests: XCTestCase {
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")
case .success(let videoDetail):
XCTAssertNotNil(videoDetail.media?.hls, "HLS stream URL should not be nil")
hlsExpectation.fulfill()
case .failure(let error):
XCTFail("Loading HLS stream failed with error: \(error.localizedDescription)")
Expand Down Expand Up @@ -126,7 +183,7 @@ class PlaybackSDKManagerTests: XCTestCase {
let hlsExpectation = expectation(description: "Empty entry id loading expectation")
manager.loadHLSStream(forEntryId: "", andAuthorizationToken: nil) { result in
switch result {
case .success(let hlsURL):
case .success(_):
XCTFail("Empty entry id provided but got HLS stream")
case .failure(let error):
switch error {
Expand All @@ -147,4 +204,10 @@ class PlaybackSDKManagerTests: XCTestCase {
// Assert that playerView is not nil or do further UI testing if possible
XCTAssertNotNil(playerView)
}

func testLoadPlaylist() {
let playerView = manager.loadPlaylist(entryIDs: playlistEntryID, authorizationToken: nil, onErrors: { _ in })
// Assert that playerView is not nil or do further UI testing if possible
XCTAssertNotNil(playerView)
}
}
1 change: 1 addition & 0 deletions Tests/PlaybackSDKTests/TestConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import Foundation
internal struct TestConfig {
static let testAPIKey = "EJEZPIezBkaf0EQ7ey5Iu2MDA2ARUkgc79eyDOnG"
static let testEntryID = "0_cmk35zei"
static let testPlaylistEntryID = ["0_cmk35zei", "0_xv365lyn"]
}

0 comments on commit 0b6e45b

Please sign in to comment.