Advertisement

← poker-tutor

Sources/PokerTests/VariantTests.swift

3.7 KB Download file
import Foundation
import PokerSession
import PokerStore
import PokerUI
import TestKit

/// The two products and what tells them apart.
func variantTests(_ t: TestRun) {
    t.suite("two products, one codebase") { t in

        t.test("the tournament app is the app that shipped") {
            // Every one of these strings is on Ken's phone already. Change one and his hands,
            // his settings and his free-hand count all quietly start over.
            let v = AppVariant.pokerTutor
            t.equal(v.format, .tournament)
            t.equal(v.displayName, "Poker Tutor")
            t.equal(v.bundleID, "com.thedigitaladlab.pokertutor")
            t.equal(v.historyFolder, "PokerTutor")
            t.equal(v.defaultsPrefix, "PokerTutor.")
            t.equal(v.storeProductID, "com.thedigitaladlab.pokertutor.yearly")
            t.equal(v.tallyKey, "trial.handsPlayed", "the tally shipped without a prefix and keeps it")
            t.equal(v.key("screen"), "PokerTutor.screen")
            t.equal(v.key("tutorialSeen"), "PokerTutor.tutorialSeen")
        }

        t.test("the cash app shares nothing that would mix the two histories") {
            let a = AppVariant.pokerTutor, b = AppVariant.pokerTutorCash
            t.equal(b.format, .cash)
            t.expect(b.isCash && !a.isCash)
            t.notEqual(a.bundleID, b.bundleID)
            t.notEqual(a.historyFolder, b.historyFolder)
            t.notEqual(a.defaultsPrefix, b.defaultsPrefix)
            t.notEqual(a.storeProductID, b.storeProductID)
            t.notEqual(a.tallyKey, b.tallyKey)
            t.expect(b.bundleID.hasPrefix(a.bundleID + "."), "the cash id sits under the same company")
            t.expect(b.historyFolder != a.historyFolder && HistoryStore.defaultURL(folder: b.historyFolder)?.path.contains("PokerTutorCash") == true)
        }

        t.test("the store sells the product the running app is") {
            let before = AppVariant.current
            defer { AppVariant.current = before }
            AppVariant.current = .pokerTutorCash
            t.equal(MainActor.assumeIsolated { SubscriptionStore.yearlyProductID }, "com.thedigitaladlab.pokertutor.cash.yearly")
            t.equal(TrialTally(store: InMemoryTally()).handsPlayed, 0)
            AppVariant.current = .pokerTutor
            t.equal(MainActor.assumeIsolated { SubscriptionStore.yearlyProductID }, "com.thedigitaladlab.pokertutor.yearly")
        }

        t.test("each product's About and privacy links go to its own pages") {
            let before = AppVariant.current
            defer { AppVariant.current = before }
            AppVariant.current = .pokerTutor
            t.equal(Copy.pokerTutorPageURL, "https://www.thedigitaladlab.com/poker-tutor")
            t.equal(Copy.privacyURL, "https://www.thedigitaladlab.com/poker-tutor-privacy")
            t.equal(Copy.readAboutPokerTutor, "About Poker Tutor")
            t.expect(Copy.versionLine("1.0").hasPrefix("Poker Tutor 1.0"), Copy.versionLine("1.0"))
            AppVariant.current = .pokerTutorCash
            t.equal(Copy.pokerTutorPageURL, "https://www.thedigitaladlab.com/poker-tutor-cash")
            t.equal(Copy.privacyURL, "https://www.thedigitaladlab.com/poker-tutor-cash-privacy")
            t.equal(Copy.readAboutPokerTutor, "About Poker Tutor Cash")
            t.expect(Copy.versionLine("1.0").hasPrefix("Poker Tutor Cash 1.0"), Copy.versionLine("1.0"))
            t.expect(Copy.madeByBlurb.hasPrefix("Poker Tutor Cash is one of"), "the About blurb names the wrong app")
        }

        t.test("the suite runs as the tournament product unless a test says otherwise") {
            t.equal(AppVariant.current, .pokerTutor)
        }
    }
}