import CottonKit @testable import CottonUI import XCTest final class CustomerShellTests: XCTestCase { private func pages(_ role: String) throws -> BusinessPages { try JSONDecoder().decode(BusinessPages.self, from: Data(BusinessFake.pages(role: role, booked: false).utf8)) } /// RULE: A business app opens on its business's door: a manifest naming its business's object (a business app's, as one shipped) opens on the business's shell, a personal app's never does (the core starts its database instead: there is no first-open choice), and the root decides it there and only there, drawing nothing else at the door. func testABusinessOpensOnItsShell() throws { for flavour in ["kitchen"] { let manifest = try JSONDecoder().decode(FlavourManifest.self, from: Data(BusinessFake.manifest(flavour).utf8)) XCTAssertEqual(manifest.genesis, .none, flavour) XCTAssertEqual(CustomerShell.opens(manifest), BusinessAddress(server: BusinessFake.server, slug: flavour)) } let development = try JSONDecoder().decode(FlavourManifest.self, from: Data( try SourceSweep.mustRead("apps/cotton/Tests/Fixtures/Flavours/development.json", ownedBy: "project2").utf8)) XCTAssertNil(CustomerShell.opens(development), "a personal app's object is its database, never a business's shell") let cotton = try JSONDecoder().decode(FlavourManifest.self, from: Data( try SourceSweep.mustRead("apps/cotton/App/CottonManifest/flavour.json", ownedBy: "shell3").utf8)) XCTAssertEqual(development.personalObject, BusinessAddress(server: "https://cottondb.com", window: ["message": 90])) // Cotton's manifest names a server per side; the test process is Cotton Dev's (`AppFlavorTests`). The source // says `{dev-host}`, which the build fills in from config/dev-server.json. XCTAssertEqual(cotton.personalObject, BusinessAddress(server: "https://{dev-host}", window: ["message": 90])) for personal in [development, cotton] { XCTAssertNil(CustomerShell.opens(personal), personal.flavour) } XCTAssertNil(CustomerShell.opens(nil), "a bundle with no manifest opens as Cotton") let root = SourceSweep.withoutComments(try SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Boot/RootView.swift", ownedBy: "shell3")) let door = try XCTUnwrap(root.range(of: "case .door:")) let next = try XCTUnwrap(root.range(of: "case .gate", range: door.upperBound..