This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ReceiptRefreshProviderTests.swift
71 lines (64 loc) · 2.16 KB
/
ReceiptRefreshProviderTests.swift
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ReceiptRefreshProviderTests.swift
// InAppPurchaseTests
//
// Created by Jin Sasaki on 2020/12/10.
// Copyright © 2020 Jin Sasaki. All rights reserved.
//
import XCTest
@testable import InAppPurchase
import StoreKit
import InAppPurchaseStubs
final class ReceiptRefreshProviderTests: XCTestCase {
let provider = ReceiptRefreshProvider()
func testMakeRequest() {
let request = provider.makeRequest(requestId: "REQUEST_001")
XCTAssertTrue(request.delegate === provider)
XCTAssertEqual(request.id, "REQUEST_001")
}
func testFetch() {
let expectation = self.expectation()
let request = StubReceiptRefreshRequest(startHandler: {
expectation.fulfill()
})
provider.fetch(request: request) { _ in }
wait(for: [expectation], timeout: 1)
}
func testFetchWithRequestWhereSuccess() {
let request = provider.makeRequest(requestId: "REQUEST_001")
let expectation = self.expectation()
provider.fetch(request: request) { (result) in
switch result {
case .success:
XCTAssert(true)
case .failure:
XCTFail()
}
expectation.fulfill()
}
provider.requestDidFinish(request)
wait(for: [expectation], timeout: 1)
}
func testFetchWithRequestWhereRequestFailure() {
let request = provider.makeRequest(requestId: "REQUEST_001")
let expectation = self.expectation()
provider.fetch(request: request) { (result) in
switch result {
case .success:
XCTFail()
case .failure(let error):
if case let .with(err) = error.code {
let err = err as NSError
XCTAssertEqual(err.domain, "test")
XCTAssertEqual(err.code, 500)
} else {
XCTFail()
}
}
expectation.fulfill()
}
let error = NSError(domain: "test", code: 500, userInfo: nil)
provider.request(request, didFailWithError: error)
wait(for: [expectation], timeout: 1)
}
}