-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(banner): add tests for topsort banner
- Loading branch information
1 parent
a33e295
commit 7515cd9
Showing
4 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import XCTest | ||
@testable import TopsortBanners | ||
@testable import Topsort_Analytics | ||
|
||
class TopsortBannerTests: XCTestCase { | ||
|
||
func testTopsortBannerInitialization() { | ||
let expectation = self.expectation(description: "Button clicked action") | ||
let banner = TopsortBanner( | ||
apiKey: "test_api_key", | ||
url: "test_url", | ||
width: 300, | ||
height: 250, | ||
slotId: "test_slot_id", | ||
deviceType: "test_device_type" | ||
) { response in | ||
expectation.fulfill() | ||
} | ||
|
||
XCTAssertEqual(banner.width, 300) | ||
XCTAssertEqual(banner.height, 250) | ||
|
||
banner.buttonClickedAction(nil) | ||
|
||
wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
func testExecuteAuctions() async { | ||
// Mock the response | ||
let asset = Asset(url: "https://example.com") | ||
let winner = Winner(rank: 1, asset: [asset], type: "type", id: "id", resolvedBidId: "resolved_bid_id") | ||
let auctionResult = AuctionResult(resultType: "result_type", winners: [winner], error: false) | ||
let auctionResponse = AuctionResponse(results: [auctionResult]) | ||
|
||
// Mock Analytics and response | ||
let mockAnalytics = MockAnalytics() | ||
mockAnalytics.executeAuctionsMockResponse = auctionResponse | ||
|
||
let banner = await TopsortBanner( | ||
apiKey: "test_api_key", | ||
url: "test_url", | ||
width: 300, | ||
height: 250, | ||
slotId: "test_slot_id", | ||
deviceType: "test_device_type", | ||
buttonClickedAction: { response in | ||
}, | ||
analytics: mockAnalytics | ||
) | ||
|
||
// Execute the method | ||
await banner.executeAuctions(deviceType: "test_device_type", slotId: "test_slot_id") | ||
|
||
await MainActor.run { | ||
XCTAssertEqual(banner.sharedValues.resolvedBidId, "resolved_bid_id") | ||
XCTAssertEqual(banner.sharedValues.urlString, "https://example.com") | ||
XCTAssertFalse(banner.sharedValues.loading) | ||
} | ||
} | ||
} |
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,32 @@ | ||
import Foundation | ||
import XCTest | ||
@testable import Topsort_Analytics | ||
|
||
public class MockAnalytics: AnalyticsProtocol { | ||
public var opaqueUserId: String = "mocked-opaque-user-id" | ||
public var executeAuctionsMockResponse: AuctionResponse? | ||
|
||
public func set(opaqueUserId: String?) { | ||
// Mock implementation | ||
} | ||
|
||
public func configure(apiKey: String, url: String? = nil) { | ||
// Mock implementation | ||
} | ||
|
||
public func track(impression event: Event) { | ||
// Mock implementation | ||
} | ||
|
||
public func track(click event: Event) { | ||
// Mock implementation | ||
} | ||
|
||
public func track(purchase event: PurchaseEvent) { | ||
// Mock implementation | ||
} | ||
|
||
public func executeAuctions(auctions: [Auction]) async -> AuctionResponse? { | ||
return executeAuctionsMockResponse | ||
} | ||
} |
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,29 @@ | ||
import XCTest | ||
@testable import TopsortBanners | ||
@testable import Topsort_Analytics | ||
|
||
class SharedValuesTests: XCTestCase { | ||
|
||
func testSharedValuesInitialization() { | ||
let sharedValues = SharedValues() | ||
|
||
XCTAssertNil(sharedValues.resolvedBidId) | ||
XCTAssertTrue(sharedValues.loading) | ||
XCTAssertNil(sharedValues.urlString) | ||
XCTAssertNil(sharedValues.response) | ||
} | ||
|
||
func testSetResolvedBidIdAndUrlFromResponse() { | ||
let asset = Asset(url: "https://example.com") | ||
let winner = Winner(rank: 1, asset: [asset], type: "type", id: "id", resolvedBidId: "resolved_bid_id") | ||
let auctionResult = AuctionResult(resultType: "result_type", winners: [winner], error: false) | ||
let auctionResponse = AuctionResponse(results: [auctionResult]) | ||
|
||
let sharedValues = SharedValues() | ||
sharedValues.response = auctionResponse | ||
sharedValues.setResolvedBidIdAndUrlFromResponse() | ||
|
||
XCTAssertEqual(sharedValues.resolvedBidId, "resolved_bid_id") | ||
XCTAssertEqual(sharedValues.urlString, "https://example.com") | ||
} | ||
} |