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
/
PaymentTransactionTests.swift
62 lines (52 loc) · 2.33 KB
/
PaymentTransactionTests.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
//
// PaymentTransactionTests.swift
// InAppPurchase
//
// Created by Jin Sasaki on 2017/09/05.
// Copyright © 2017年 Jin Sasaki. All rights reserved.
//
import XCTest
@testable import InAppPurchase
import InAppPurchaseStubs
import StoreKit
class PaymentTransactionTests: XCTestCase {
func testTransactionState() {
XCTAssertEqual(PaymentTransaction.State.purchasing, PaymentTransaction.State(.purchasing))
XCTAssertEqual(PaymentTransaction.State.purchased, PaymentTransaction.State(.purchased))
XCTAssertEqual(PaymentTransaction.State.failed, PaymentTransaction.State(.failed))
XCTAssertEqual(PaymentTransaction.State.restored, PaymentTransaction.State(.restored))
XCTAssertEqual(PaymentTransaction.State.deferred, PaymentTransaction.State(.deferred))
XCTAssertEqual(PaymentTransaction.State.unknown(rawValue: 10), PaymentTransaction.State(SKPaymentTransactionState(rawValue: 10) ?? .deferred))
}
func testInit() {
let original = StubPaymentTransaction(
transactionIdentifier: "ORIGINAL_TRANSACTION_001",
transactionState: .purchased
)
let payment = StubPayment(productIdentifier: "PRODUCT_001")
let skTransaction = StubPaymentTransaction(
transactionIdentifier: "TRANSACTION_001",
transactionState: .restored,
original: original,
payment: payment
)
let transaction = PaymentTransaction(skTransaction)
XCTAssertEqual(transaction.transactionIdentifier, "TRANSACTION_001")
XCTAssertEqual(transaction.originalTransactionIdentifier, "ORIGINAL_TRANSACTION_001")
XCTAssertEqual(transaction.productIdentifier, "PRODUCT_001")
XCTAssertEqual(transaction.state, .restored)
XCTAssertEqual(transaction.original?.transactionIdentifier, "ORIGINAL_TRANSACTION_001")
XCTAssertEqual(transaction.original?.state, .purchased)
}
func testInitWithoutOriginal() {
let payment = StubPayment(productIdentifier: "PRODUCT_001")
let skTransaction = StubPaymentTransaction(
transactionIdentifier: "TRANSACTION_001",
transactionState: .restored,
original: nil,
payment: payment
)
let transaction = PaymentTransaction(skTransaction)
XCTAssertNil(transaction.original)
}
}