DomainDigTests/FeatureAccessTests.swift

2ad5d8160338d289a65d6a4d1c214a02bf916f1f
domain-dig/DomainDigTests/FeatureAccessTests.swift history · blame · raw

177 lines · 8219 bytes

18 symbols in this file
  1import XCTest
  2@testable import DomainDig
  3
  4/// The tier table used to promise five capabilities that could not return data,
  5/// and they were Pro+'s only difference from Pro — so making the paywall honest
  6/// by deleting them would have left a paid tier granting nothing. These pin the
  7/// replacement table and that invariant.
  8final class FeatureAccessTests: XCTestCase {
  9
 10    // MARK: Free
 11
 12    func testFreeIncludesTheEverydayCapabilities() {
 13        let free = FeatureAccessService.entitlements(for: .free)
 14
 15        XCTAssertTrue(free.capabilities.contains(.singleLookup))
 16        XCTAssertTrue(free.capabilities.contains(.basicHistory))
 17        XCTAssertTrue(free.capabilities.contains(.limitedTracking))
 18        XCTAssertTrue(free.capabilities.contains(.workflows))
 19        XCTAssertTrue(free.capabilities.contains(.batchOperations))
 20    }
 21
 22    func testFreeExcludesThePaidCapabilities() {
 23        let free = FeatureAccessService.entitlements(for: .free)
 24
 25        XCTAssertFalse(free.capabilities.contains(.automatedMonitoring))
 26        XCTAssertFalse(free.capabilities.contains(.localAlerts))
 27        XCTAssertFalse(free.capabilities.contains(.advancedExports))
 28        XCTAssertFalse(free.capabilities.contains(.extendedSubdomains))
 29        XCTAssertFalse(free.capabilities.contains(.sharedPortfolios))
 30        XCTAssertFalse(free.capabilities.contains(.auditDepth))
 31    }
 32
 33    func testFreeKeepsItsAllowances() {
 34        let free = FeatureAccessService.entitlements(for: .free)
 35
 36        XCTAssertEqual(free.trackedDomainLimit, 5)
 37        XCTAssertEqual(free.workflowLimit, 1)
 38        XCTAssertEqual(free.batchSizeLimit, 10)
 39        XCTAssertEqual(free.activeAuditSessionLimit, 1)
 40    }
 41
 42    // MARK: Pro
 43
 44    /// Extended subdomains moved down from Pro+: unlike the other four, it does
 45    /// return data a lower tier does not have — a live crt.sh query at a higher
 46    /// limit than the base lookup.
 47    func testProAddsMonitoringAlertsExportsAndExtendedSubdomains() {
 48        let pro = FeatureAccessService.entitlements(for: .pro)
 49
 50        XCTAssertTrue(pro.capabilities.contains(.automatedMonitoring))
 51        XCTAssertTrue(pro.capabilities.contains(.localAlerts))
 52        XCTAssertTrue(pro.capabilities.contains(.advancedExports))
 53        XCTAssertTrue(pro.capabilities.contains(.extendedSubdomains))
 54    }
 55
 56    func testProDoesNotIncludeTheProPlusCapabilities() {
 57        let pro = FeatureAccessService.entitlements(for: .pro)
 58
 59        XCTAssertFalse(pro.capabilities.contains(.sharedPortfolios))
 60        XCTAssertFalse(pro.capabilities.contains(.auditDepth))
 61        XCTAssertFalse(pro.capabilities.contains(.intelligenceDetail))
 62    }
 63
 64    func testProLiftsTheAllowances() {
 65        let pro = FeatureAccessService.entitlements(for: .pro)
 66
 67        XCTAssertNil(pro.workflowLimit)
 68        XCTAssertNil(pro.batchSizeLimit)
 69        XCTAssertNil(pro.activeAuditSessionLimit)
 70        XCTAssertGreaterThan(pro.trackedDomainLimit, 1000)
 71    }
 72
 73    // MARK: Pro+
 74
 75    func testProPlusAddsSharedPortfoliosAuditDepthAndIntelligence() {
 76        let proPlus = FeatureAccessService.entitlements(for: .proPlus)
 77
 78        XCTAssertTrue(proPlus.capabilities.contains(.sharedPortfolios))
 79        XCTAssertTrue(proPlus.capabilities.contains(.auditDepth))
 80        XCTAssertTrue(proPlus.capabilities.contains(.intelligenceDetail))
 81    }
 82
 83    /// The intelligence breakdown was gated by a bare `currentTier != .proPlus`
 84    /// in two view bodies, which no audit of the capability table could see. It
 85    /// is a capability now so the table, the paywall and `enabledFeatureLabels`
 86    /// all agree, and so a test like this one can exist at all.
 87    func testIntelligenceDetailIsAProPlusCapability() {
 88        XCTAssertFalse(FeatureAccessService.entitlements(for: .free).capabilities.contains(.intelligenceDetail))
 89        XCTAssertFalse(FeatureAccessService.entitlements(for: .pro).capabilities.contains(.intelligenceDetail))
 90        XCTAssertTrue(FeatureAccessService.entitlements(for: .proPlus).capabilities.contains(.intelligenceDetail))
 91    }
 92
 93    /// The finding this table replaces: Pro+ cost twice Pro and its only
 94    /// difference was five capabilities that returned nothing. A tier that
 95    /// grants no more than the one below it must not be sellable.
 96    func testProPlusGrantsStrictlyMoreThanPro() {
 97        let pro = FeatureAccessService.entitlements(for: .pro).capabilities
 98        let proPlus = FeatureAccessService.entitlements(for: .proPlus).capabilities
 99
100        XCTAssertTrue(pro.isSubset(of: proPlus))
101        XCTAssertFalse(proPlus.subtracting(pro).isEmpty)
102    }
103
104    func testEachTierGrantsAtLeastTheOneBelowIt() {
105        let free = FeatureAccessService.entitlements(for: .free).capabilities
106        let pro = FeatureAccessService.entitlements(for: .pro).capabilities
107
108        XCTAssertTrue(free.isSubset(of: pro))
109    }
110
111    // MARK: Nothing claims a capability that cannot produce data
112
113    /// Pricing and reputation had no local fallback and no configured endpoint,
114    /// so they were deleted rather than renamed. Their absence from the
115    /// capability list is what stops the paywall advertising them again.
116    func testNoCapabilityIsNamedForADeletedFeature() {
117        let names = FeatureCapability.allCases.map(\.rawValue)
118
119        XCTAssertFalse(names.contains("domainPricing"))
120        XCTAssertFalse(names.contains("reputation"))
121    }
122
123    /// Ownership and DNS history derive from the user's own stored snapshots, so
124    /// they are free features now and no longer gated at all.
125    func testTheHistoryDerivationsAreNotGated() {
126        let names = FeatureCapability.allCases.map(\.rawValue)
127
128        XCTAssertFalse(names.contains("ownershipHistory"))
129        XCTAssertFalse(names.contains("dnsHistory"))
130    }
131
132    // MARK: Retention
133
134    /// The dial D1 settled on. These are the numbers the paywall promises and
135    /// the store enforces, so they are pinned here rather than inferred.
136    func testEachTierHasItsRetentionLimit() {
137        XCTAssertEqual(FeatureAccessService.entitlements(for: .free).historyRetentionLimit, 50)
138        XCTAssertEqual(FeatureAccessService.entitlements(for: .pro).historyRetentionLimit, 250)
139        XCTAssertEqual(FeatureAccessService.entitlements(for: .proPlus).historyRetentionLimit, 2_000)
140    }
141
142    func testRetentionRisesWithTheTier() {
143        let free = FeatureAccessService.entitlements(for: .free).historyRetentionLimit
144        let pro = FeatureAccessService.entitlements(for: .pro).historyRetentionLimit
145        let proPlus = FeatureAccessService.entitlements(for: .proPlus).historyRetentionLimit
146
147        XCTAssertLessThan(free, pro)
148        XCTAssertLessThan(pro, proPlus)
149    }
150
151    // MARK: Downgrade safety
152
153    /// A lapsed subscriber keeps data above the new ceiling. Nothing may refuse
154    /// to read it: the limits gate adding, not holding.
155    func testFreeTierStillReportsALimitWhenAlreadyOverIt() {
156        let free = FeatureAccessService.entitlements(for: .free)
157
158        XCTAssertFalse(FeatureAccessService.canAddTrackedDomain(currentCount: free.trackedDomainLimit, tier: .free))
159        XCTAssertTrue(FeatureAccessService.canAddTrackedDomain(currentCount: 0, tier: .free))
160        XCTAssertFalse(FeatureAccessService.canAddTrackedDomain(currentCount: 500, tier: .free))
161        XCTAssertTrue(FeatureAccessService.canAddTrackedDomain(currentCount: 500, tier: .pro))
162    }
163
164    /// Export to the user's own bucket is Pro+ (D1). Pro+ takes
165    /// `allCases`, so a new capability lands there by construction — this is
166    /// the check that it did not also land in free or pro.
167    func testBucketExportIsProPlusOnly() {
168        XCTAssertFalse(FeatureAccessService.entitlements(for: .free).capabilities.contains(.bucketExport))
169        XCTAssertFalse(FeatureAccessService.entitlements(for: .pro).capabilities.contains(.bucketExport))
170        XCTAssertTrue(FeatureAccessService.entitlements(for: .proPlus).capabilities.contains(.bucketExport))
171    }
172
173    func testBucketExportPromptsForProPlus() {
174        XCTAssertEqual(FeatureAccessService.upgradeMessage(for: .bucketExport), "Available in Pro+")
175        XCTAssertEqual(FeatureAccessService.upgradePrompt(for: .bucketExport).title, "Available in Pro+")
176    }
177}