-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathTestStoreKit.swift
More file actions
52 lines (44 loc) · 1.49 KB
/
TestStoreKit.swift
File metadata and controls
52 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import PMKStoreKit
import PromiseKit
import StoreKit
import XCTest
class SKProductsRequestTests: XCTestCase {
func test() {
class MockProductsRequest: SKProductsRequest {
override func start() {
after(seconds: 0.1).done {
self.delegate?.productsRequest(self, didReceive: SKProductsResponse())
}
}
}
let ex = expectation(description: "")
MockProductsRequest().start(.promise).done { _ in
ex.fulfill()
}
waitForExpectations(timeout: 1, handler: nil)
}
}
//////////////////////////////////////////////////////////// Cancellation
extension SKProductsRequestTests {
func testCancel() {
class MockProductsRequest: SKProductsRequest {
var isCancelled = false
override func start() {
after(seconds: 0.1).done {
if !self.isCancelled {
self.delegate?.productsRequest(self, didReceive: SKProductsResponse())
}
}
}
}
let ex = expectation(description: "")
let request = MockProductsRequest()
cancellable(request.start(.promise)).done { _ in
XCTFail()
}.catch(policy: .allErrors) {
$0.isCancelled ? ex.fulfill() : XCTFail()
}.cancel()
request.isCancelled = true
waitForExpectations(timeout: 1, handler: nil)
}
}