Files
ccn/Services/Website/Tests/App/ConfigReaderPropertiesTests.swift
T

71 lines
1.9 KiB
Swift
Raw Normal View History

import Configuration
import Infrastructure
import Persistence
import Testing
@testable import Website
@testable import WebsiteLibrary
@Suite("ConfigReader properties")
struct ConfigReaderPropertiesTests {
// MARK: Functional tests
@Test
func `analytics to default to the production tracker`() throws {
let analytics = try #require(reader().analytics)
#expect(analytics.scriptURL == .Analytics.scriptURL)
#expect(analytics.websiteID == .Analytics.websiteID)
#expect(analytics.domains == .Analytics.domains)
#expect(analytics.excludeHash)
#expect(analytics.doNotTrack)
#expect(analytics.performance)
#expect(analytics.recorder)
}
@Test
func `analytics to switch recorder mode off when configured`() throws {
let analytics = try #require(reader(values: [
.Analytics.recorder: false
]).analytics)
#expect(!analytics.recorder)
}
@Test
func `analytics to override the website id and domains when configured`() throws {
let analytics = try #require(reader(values: [
.Analytics.websiteID: "custom-website-id",
.Analytics.domains: "staging.loud.amsterdam"
]).analytics)
#expect(analytics.websiteID == "custom-website-id")
#expect(analytics.domains == "staging.loud.amsterdam")
#expect(analytics.scriptURL == .Analytics.scriptURL)
}
@Test
func `analytics to be omitted when the website id is cleared`() {
#expect(reader(values: [.Analytics.websiteID: ""]).analytics == nil)
}
}
// MARK: - Helpers
private extension ConfigReaderPropertiesTests {
// MARK: Methods
/// Builds a configuration reader over the given in-memory values alone.
func reader(
values: [AbsoluteConfigKey: ConfigValue] = [:]
) -> ConfigReader {
ConfigReader(providers: [
InMemoryProvider(values: values)
])
}
}