Tests/OrgAppTests/TipTests.swift
47 lines · 1465 bytes
7 symbols in this file
1import Foundation
2import Testing
3@testable import OrgApp
4
5struct TipTests {
6 @Test func productIDsMatchAppStoreConnectInOrder() {
7 #expect(Tip.productIDs == [
8 "sh.krz.orgstar.tip.small",
9 "sh.krz.orgstar.tip.medium",
10 "sh.krz.orgstar.tip.large",
11 ])
12 }
13
14 @Test func productIDsAreNotOrgstarPlus() {
15 // Tips must never count as an orgstar+ purchase.
16 #expect(Tip.productIDs.allSatisfy { !$0.hasPrefix("sh.krz.orgstar.pro.") })
17 }
18}
19
20#if canImport(StoreKit)
21@MainActor
22struct ProStoreTests {
23 @Test func productIDsAreOrgstarPlusAndNotTips() {
24 #expect(ProStore.productIDs == [
25 "sh.krz.orgstar.pro.monthly",
26 "sh.krz.orgstar.pro.yearly",
27 "sh.krz.orgstar.pro.lifetime",
28 ])
29 #expect(Set(ProStore.productIDs).isDisjoint(with: Tip.productIDs))
30 }
31
32 @Test func grandfathersOnlyOnIOS() {
33 #if os(iOS)
34 #expect(ProStore.grandfathers)
35 #else
36 #expect(!ProStore.grandfathers)
37 #endif
38 }
39
40 @Test func yearlySavingsAreWholePercentAgainstTwelveMonths() {
41 #expect(ProStore.yearlySavings(yearly: Decimal(string: "39.99")!, monthly: Decimal(string: "4.99")!) == 33)
42 #expect(ProStore.yearlySavings(yearly: 60, monthly: 5) == nil)
43 #expect(ProStore.yearlySavings(yearly: 70, monthly: 5) == nil)
44 #expect(ProStore.yearlySavings(yearly: 10, monthly: 0) == nil)
45 }
46}
47#endif