2025-02-04 21:57:47 +01:00
|
|
|
import ColibriLibrary
|
|
|
|
import Foundation
|
|
|
|
import Testing
|
|
|
|
|
|
|
|
struct TemplateServiceTests {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
private let spy = TemplateServiceSpy()
|
|
|
|
|
|
|
|
// MARK: Functions tests
|
|
|
|
|
|
|
|
@Test(arguments: [String.content])
|
|
|
|
func render(_ content: String) async throws {
|
|
|
|
// GIVEN
|
|
|
|
let service = TemplateServiceMock(action: .render(content), spy: spy)
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
let result = try await service.render([:], on: .template)
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
#expect(result == content)
|
|
|
|
|
|
|
|
#expect(spy.actions.isEmpty == false)
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test(arguments: [TemplateServiceError.serviceNotInitialized, .resourcePathNotFound, .templateNotFound, .contentNotRendered])
|
|
|
|
func render(throws error: TemplateServiceError) async throws {
|
2025-02-08 10:22:52 +01:00
|
|
|
// GIVEN
|
2025-02-04 21:57:47 +01:00
|
|
|
let service = TemplateServiceMock(action: .error(error), spy: spy)
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
// THEN
|
|
|
|
await #expect(throws: error) {
|
|
|
|
try await service.render([:], on: .template)
|
|
|
|
}
|
|
|
|
|
|
|
|
#expect(spy.actions.isEmpty == true)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - String+Constants
|
|
|
|
|
|
|
|
private extension String {
|
|
|
|
static let content = ""
|
|
|
|
static let template = ""
|
|
|
|
}
|