This PR contains the work done to do a little bit of housekeeping pass across all packages and the Website service. To provide further details about the work: * Refreshed the READMEs and source documentation to match the current code; * Tagged every test case consistently across the Infrastructure, Localization, Persistence, and Website test targets; * Removed Website middleware tests now covered by Infrastructure's own suite; * Conformed the `PrepareDB` method to Sendable; * Relaxes the production Compose DATABASE_TLS default from require to prefer; * Added Persistence test verifying the prefer posture falls back to plaintext connections. Reviewed-on: rock-n-code/loud-amsterdam#27 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
83 lines
2.0 KiB
Swift
83 lines
2.0 KiB
Swift
import Testing
|
|
|
|
@testable import Infrastructure
|
|
|
|
@Suite(
|
|
"Asset protocol",
|
|
.tags(.`protocol`)
|
|
)
|
|
struct AssetTests {
|
|
|
|
// MARK: Properties
|
|
|
|
private let image = StubAsset(
|
|
fileExtensions: [.png],
|
|
fileName: "icon"
|
|
)
|
|
private let shared = StubAsset(
|
|
fileExtensions: [.css, .js],
|
|
fileName: "shared"
|
|
)
|
|
|
|
// MARK: Method tests
|
|
|
|
@Test
|
|
func `relative path nests the file inside its extension's sub-directory`() {
|
|
#expect(shared.relativePath(for: .css) == "css/shared.css")
|
|
#expect(shared.relativePath(for: .js) == "js/shared.js")
|
|
}
|
|
|
|
@Test
|
|
func `relative path keeps the file at the root without a sub-directory`() {
|
|
#expect(image.relativePath(for: .png) == "icon.png")
|
|
}
|
|
|
|
@Test
|
|
func `url path prefixes the relative path with a slash`() {
|
|
#expect(shared.urlPath(for: .css) == "/css/shared.css")
|
|
#expect(image.urlPath(for: .png) == "/icon.png")
|
|
}
|
|
|
|
@Test
|
|
func `url path appends a version token as a query parameter`() {
|
|
#expect(shared.urlPath(
|
|
for: .css,
|
|
version: "0123456789abcdef"
|
|
) == "/css/shared.css?v=0123456789abcdef")
|
|
}
|
|
|
|
@Test(arguments: [nil, ""] as [String?])
|
|
func `url path without a version`(
|
|
version: String?
|
|
) {
|
|
#expect(shared.urlPath(
|
|
for: .css,
|
|
version: version
|
|
) == "/css/shared.css")
|
|
}
|
|
|
|
@Test(arguments: [
|
|
"",
|
|
".",
|
|
"Resources/Static"
|
|
])
|
|
func `path relative to`(
|
|
_ basePath: String
|
|
) {
|
|
for fileExtension in shared.fileExtensions {
|
|
let pathRelativeToBasePath = shared.path(
|
|
relativeTo: basePath,
|
|
for: fileExtension
|
|
)
|
|
let relativePath = shared.relativePath(for: fileExtension)
|
|
|
|
if basePath.isEmpty {
|
|
#expect(pathRelativeToBasePath == relativePath)
|
|
} else {
|
|
#expect(pathRelativeToBasePath == "\(basePath)/\(relativePath)")
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|