forked from segmentio/analytics-ios
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for SEGStoreKitTracker and UIViewController+SEGScreen (segm…
…entio#687) * Adding OCMockito * Adding test case for SEGStoreKitTracker * Adding tests for UIViewController+SEGScreen
- Loading branch information
Showing
9 changed files
with
140 additions
and
10 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
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
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,49 @@ | ||
// | ||
// ScreenTrackerTests.swift | ||
// Analytics | ||
// | ||
// Created by Tony Xiao on 9/20/16. | ||
// Copyright © 2016 Segment. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
import Analytics | ||
|
||
var staticMockVC: UIViewController! | ||
|
||
class mockViewController: UIViewController { | ||
override class func seg_top() -> UIViewController? { | ||
return staticMockVC | ||
} | ||
} | ||
|
||
class ScreenTrackerTests: QuickSpec { | ||
override func spec() { | ||
|
||
var test: TestMiddleware! | ||
|
||
beforeEach { | ||
let config = SEGAnalyticsConfiguration(writeKey: "foobar") | ||
test = TestMiddleware() | ||
config.middlewares = [test] | ||
// This is really not ideal to be using a global | ||
// singleton, but don't have better choices atm | ||
SEGAnalytics.setup(with: config) | ||
} | ||
|
||
it("tracks screen with correct title") { | ||
UIViewController.seg_swizzleViewDidAppear() | ||
staticMockVC = mockViewController() | ||
staticMockVC.title = "Mock Screen" | ||
staticMockVC.viewDidLoad() | ||
staticMockVC.viewWillAppear(true) | ||
staticMockVC.viewDidAppear(true) | ||
|
||
let payload = test.lastContext?.payload as? SEGScreenPayload | ||
expect(payload?.name) == "Mock Screen" | ||
} | ||
|
||
} | ||
|
||
} |
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,71 @@ | ||
// | ||
// StoreKitTrackerTest.swift | ||
// Analytics | ||
// | ||
// Created by Tony Xiao on 9/20/16. | ||
// Copyright © 2016 Segment. All rights reserved. | ||
// | ||
|
||
import Quick | ||
import Nimble | ||
import Analytics | ||
|
||
class mockTransaction: SKPaymentTransaction { | ||
override var transactionIdentifier: String? { | ||
return "tid" | ||
} | ||
override var transactionState: SKPaymentTransactionState { | ||
return SKPaymentTransactionState.purchased | ||
} | ||
override var payment: SKPayment { | ||
return mockPayment() | ||
} | ||
} | ||
|
||
class mockPayment: SKPayment { | ||
override var productIdentifier: String { return "pid" } | ||
} | ||
|
||
class mockProduct: SKProduct { | ||
override var productIdentifier: String { return "pid" } | ||
override var price: NSDecimalNumber { return 3 } | ||
override var localizedTitle: String { return "lt" } | ||
|
||
} | ||
|
||
class mockProductResponse: SKProductsResponse { | ||
override var products: [SKProduct] { | ||
return [mockProduct()] | ||
} | ||
} | ||
|
||
class StoreKitTrackerTests: QuickSpec { | ||
override func spec() { | ||
|
||
var test: TestMiddleware! | ||
var tracker: SEGStoreKitTracker! | ||
var analytics: SEGAnalytics! | ||
|
||
beforeEach { | ||
let config = SEGAnalyticsConfiguration(writeKey: "foobar") | ||
test = TestMiddleware() | ||
config.middlewares = [test] | ||
analytics = SEGAnalytics(configuration: config) | ||
tracker = SEGStoreKitTracker.trackTransactions(for: analytics) | ||
} | ||
|
||
it("SKPaymentQueue Observer") { | ||
let transaction = mockTransaction() | ||
expect(transaction.transactionIdentifier) == "tid" | ||
tracker.paymentQueue(SKPaymentQueue(), updatedTransactions: [transaction]) | ||
|
||
tracker.productsRequest(SKProductsRequest(), didReceive: mockProductResponse()) | ||
|
||
let payload = test.lastContext?.payload as? SEGTrackPayload | ||
|
||
expect(payload?.event) == "Order Completed" | ||
} | ||
|
||
} | ||
|
||
} |
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