Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Surcharges/DomainLayer/UseCases/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ let target = surcharges.target(
]
)

let project = surcharges.project(targets: [target])
let tests = surcharges.test(
projects: [
DomainLayer.UseCases,
DataLayer.RepositoryProtocols,
]
)

let project = surcharges.project(targets: [target, tests])
21 changes: 21 additions & 0 deletions Surcharges/DomainLayer/UseCases/Tests/GetPlaceUsecaseTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// GetPlaceUsecaseTests.swift
// UseCasesTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation
import Testing

import Entities
import UseCases

@Test("GetPlaces")
func getPlaces() async throws {
await #expect(throws: GetPlacesError.noResults) {
try await GetPlacesUsecase(placeRepository: PlaceRepositoryMock())
.invoke(requestValue: .init(searchText: "", nextPageToken: nil, userLocation: nil))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppStatusServiceMock.swift
// UseCasesTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation

import AppStatusServiceProtocol

public final class AppStatusServiceMock: AppStatusServiceProtocol {
public var appStatus: AppStatus?

public func notifyAppStatus(_ status: AppStatus) { }
}
18 changes: 18 additions & 0 deletions Surcharges/DomainLayer/UseCases/Tests/Mocks/EndPointMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// EndPointMock.swift
// UseCasesTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation

import EndpointProtocol

public struct EndPointMock: EndpointProtocol {
public init() {}
public var baseURL: String { "" }
public var authorisationScheme: String { "" }
public var authorisationToken: String { "" }
}
13 changes: 13 additions & 0 deletions Surcharges/DomainLayer/UseCases/Tests/Mocks/NetworkErrorMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// NetworkErrorMock.swift
// UseCasesTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation

public enum NetworkErrorMock: Error {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PlaceRepositoryMock.swift
// UseCasesTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation

import DTOs
import RepositoryProtocols

public struct PlaceRepositoryMock: PlaceRepositoryProtocol {

public typealias AppStatusService = AppStatusServiceMock
public typealias Endpoint = EndPointMock

public func getPlaces(request: GetPlacesRequest) async throws(GetPlacesError) -> GetPlacesResponse {
throw .notFound
}

public func getPlace(request: GetPlaceRequest) async throws(GetPlaceError) -> GetPlaceResponse {
throw .notFound
}

public func errorHandlerExceptNotFound(appStatusService: AppStatusService, error: NetworkErrorMock) async { }

}
9 changes: 8 additions & 1 deletion Surcharges/PresentationLayer/ViewModels/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ let target = surcharges.target(
]
)

let project = surcharges.project(targets: [target])
let tests = surcharges.test(
projects: [
PresentationLayer.ViewModels,
DomainLayer.UseCaseProtocols,
]
)

let project = surcharges.project(targets: [target, tests])
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MainViewModel.swift
// ViewModelsTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation
import Testing

import ViewUpdateServiceProtocol
import ViewModels

@MainActor
struct MainViewModelTests {

let mainViewModel = MainViewModel(
getPlaces: GetPlacesUsecaseMock(),
locationService: LocationServiceMock(),
viewUpdateService: ViewUpdateServiceMock()
)

@Test("Places count must 1")
func mainViewModel() async throws {
await mainViewModel.search()

#expect(mainViewModel.mainModel.places.count == 1)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// GetPlacesUsecaseMock.swift
// ViewModelsTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation

import UseCaseProtocols
import Entities

struct GetPlacesUsecaseMock: GetPlacesUsecaseProtocol {
func invoke(requestValue: GetPlacesRequest) async throws(GetPlacesError) -> GetPlacesResponse {
return .init(
items: [
.init(
place: .init(
id: "id",
displayName: .init(text: "displayName", languageCode: "en"),
addressComponents: [],
location: nil
),
surcharge: .init(status: .unknown, rate: nil, updatedDate: nil)
)
],
nextPageToken: nil
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// LocationServiceMock.swift
// ViewModelsTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation
import Combine
import CoreLocation

import LocationServiceProtocol

struct LocationServiceMock: LocationServiceProtocol {
var authorizationStatus = PassthroughSubject<CLAuthorizationStatus, Never>()

func getLocation() async throws -> CLLocation {
return .init(latitude: 0, longitude: 0)
}

func requestWhenInUseAuthorization() { }


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ViewUpdateServiceMock.swift
// ViewModelsTests
//
// Created by Bonsung Koo on 29/01/2025.
// Copyright © 2025 Surcharges. All rights reserved.
//

import Foundation
import Combine

import ViewUpdateServiceProtocol

final class ViewUpdateServiceMock: ViewUpdateServiceProtocol {
var notified = PassthroughSubject<ViewUpdateType, Never>()

func update(_ item: ViewUpdateType) async { }
}
8 changes: 0 additions & 8 deletions Surcharges/Tests/SurchargesTests.swift

This file was deleted.

Loading