Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseCase 테스트 추가 #81

Merged
merged 6 commits into from
Jan 19, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "2.2">
version = "2.1">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand Down
7 changes: 7 additions & 0 deletions InMyMemory.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
"identifier" : "HomePresentationTests",
"name" : "HomePresentationTests"
}
},
{
"target" : {
"containerPath" : "container:InMyMemory\/Domain",
"identifier" : "UseCaseTests",
"name" : "UseCaseTests"
}
}
],
"version" : 1
Expand Down
14 changes: 14 additions & 0 deletions InMyMemory/Domain/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ let package = Package(
.package(path: "../Shared"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.6.0")),
.package(url: "https://github.com/Swinject/Swinject.git", .upToNextMajor(from: "2.8.4")),
.package(url: "https://github.com/Quick/Quick.git", from: "7.3.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "13.1.2"),
],
targets: [
.target(
Expand All @@ -47,5 +49,17 @@ let package = Package(
.product(name: "CoreKit", package: "Shared"),
]
),
.testTarget(
name: "UseCaseTests",
dependencies: [
"UseCases",
"Entities",
"Interfaces",
"RxSwift",
.product(name: "CoreKit", package: "Shared"),
"Quick",
"Nimble"
]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// EmotionRepositoryMock.swift
//
//
// Created by 홍성준 on 1/19/24.
//

import Foundation
import Interfaces
import Entities
import RxSwift

final class EmotionRepositoryMock: EmotionRepositoryInterface {

init() {}

var createEmotionCallCount = 0
var createEmotionEmotion: Emotion?
func create(emotion: Emotion) -> Single<Void> {
createEmotionCallCount += 1
createEmotionEmotion = emotion
return .just(())
}

var readEmotionIDCallCount = 0
var readEmotionIDEmotionID: UUID?
var readEmotionIDEmotion: Emotion?
func read(emotionID: UUID) -> Single<Emotion?> {
readEmotionIDCallCount += 1
readEmotionIDEmotionID = emotionID
return .just(readEmotionIDEmotion)
}

Check warning on line 32 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift#L28-L32

Added lines #L28 - L32 were not covered by tests

var readGreaterThanCallCount = 0
var readGreaterThanDate: Date?
var readGreaterThanEmotions: [Emotion] = []
func read(greaterThan date: Date) -> Single<[Emotion]> {
readGreaterThanCallCount += 1
readGreaterThanDate = date
return .just(readGreaterThanEmotions)
}

var readGreaterOrEqualThanLessThanCallCount = 0
var readGreaterOrEqualThanLessThanGreaterOrEqualDate: Date?
var readGreaterOrEqualThanLessThanLessDate: Date?
var readGreaterOrEqualThanLessThanEmotions: [Emotion] = []
func read(greaterOrEqualThan greaterOrEqualDate: Date, lessThan lessDate: Date) -> Single<[Emotion]> {
readGreaterOrEqualThanLessThanCallCount += 1
readGreaterOrEqualThanLessThanGreaterOrEqualDate = greaterOrEqualDate
readGreaterOrEqualThanLessThanLessDate = lessDate
return .just(readGreaterOrEqualThanLessThanEmotions)
}

Check warning on line 52 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift#L47-L52

Added lines #L47 - L52 were not covered by tests

var readKeywordCallCount = 0
var readKeywordKeyword: String?
var readKeywordEmotions: [Emotion] = []
func read(keyword: String) -> Single<[Emotion]> {
readKeywordCallCount += 1
readKeywordKeyword = keyword
return .just(readKeywordEmotions)
}

var updateEmotionCallCount = 0
var updateEmotionEmotion: Emotion?
func update(emotion: Emotion) -> Single<Void> {
updateEmotionCallCount += 1
updateEmotionEmotion = emotion
return .just(())
}

Check warning on line 69 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift#L65-L69

Added lines #L65 - L69 were not covered by tests

var deleteEmotionCallCount = 0
var deleteEmotionEmotion: Emotion?
func delete(emotion: Emotion) -> Single<Void> {
deleteEmotionCallCount += 1
deleteEmotionEmotion = emotion
return .just(())
}

Check warning on line 77 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/EmotionRepositoryMock.swift#L73-L77

Added lines #L73 - L77 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// MemoryRepositoryMock.swift
//
//
// Created by 홍성준 on 1/19/24.
//

import Foundation
import Interfaces
import Entities
import RxSwift

final class MemoryRepositoryMock: MemoryRepositoryInterface {

init() {}

var createMemoryCallCount = 0
var createMemoryMemory: Memory?
func create(memory: Memory) -> Single<Void> {
createMemoryCallCount += 1
createMemoryMemory = memory
return .just(())
}

Check warning on line 23 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift#L19-L23

Added lines #L19 - L23 were not covered by tests

var readMemoryIDCallCount = 0
var readMemoryIDMemoryID: UUID?
var readMemoryIDMemory: Memory?
func read(memoryID: UUID) -> Single<Memory?>{
readMemoryIDCallCount += 1
readMemoryIDMemoryID = memoryID
return .just(readMemoryIDMemory)
}

var readGreaterThanCallCount = 0
var readGreaterThanDate: Date?
var readGreaterThanMemories: [Memory] = []
func read(greaterThan date: Date) -> Single<[Memory]> {
readGreaterThanCallCount += 1
readGreaterThanDate = date
return .just(readGreaterThanMemories)
}

var readGreaterOrEqualThanLessThanCallCount = 0
var readGreaterOrEqualThanLessThanGreaterOrEqualDate: Date?
var readGreaterOrEqualThanLessThanLessDate: Date?
var readGreaterOrEqualThanLessThanMemories: [Memory] = []
func read(greaterOrEqualThan greaterOrEqualDate: Date, lessThan lessDate: Date) -> Single<[Memory]> {
readGreaterOrEqualThanLessThanCallCount += 1
readGreaterOrEqualThanLessThanGreaterOrEqualDate = greaterOrEqualDate
readGreaterOrEqualThanLessThanLessDate = lessDate
return .just(readGreaterOrEqualThanLessThanMemories)
}

Check warning on line 52 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift#L47-L52

Added lines #L47 - L52 were not covered by tests

var readKeywordCallCount = 0
var readKeywordKeyword: String?
var readKeywordMemories: [Memory] = []
func read(keyword: String) -> Single<[Memory]> {
readKeywordCallCount += 1
readKeywordKeyword = keyword
return .just(readKeywordMemories)
}

var updateMemoryCallCount = 0
var updateMemoryMemory: Memory?
func update(memory: Memory) -> Single<Void> {
updateMemoryCallCount += 1
updateMemoryMemory = memory
return .just(())
}

var deleteMemoryCallCount = 0
var deleteMemoryMemory: Memory?
func delete(memory: Memory) -> Single<Void> {
deleteMemoryCallCount += 1
deleteMemoryMemory = memory
return .just(())
}

Check warning on line 77 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/MemoryRepositoryMock.swift#L73-L77

Added lines #L73 - L77 were not covered by tests

var deleteMemoryIDCallCount = 0
var deleteMemoryIDMemoryID: UUID?
func delete(memoryID: UUID) -> Single<Void> {
deleteMemoryIDCallCount += 1
deleteMemoryIDMemoryID = memoryID
return .just(())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// TodoRepositoryMock.swift
//
//
// Created by 홍성준 on 1/19/24.
//

import Foundation
import Interfaces
import Entities
import RxSwift

final class TodoRepositoryMock: TodoRepositoryInterface {

init() {}

var createTodoCallCount = 0
var createTodoTodo: Todo?
func create(todo: Todo) -> Single<Void> {
createTodoCallCount += 1
createTodoTodo = todo
return .just(())
}

Check warning on line 23 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift#L19-L23

Added lines #L19 - L23 were not covered by tests

var readTodoIDCallCount = 0
var readTodoIDTodoID: UUID?
var readTodoIDTodo: Todo?
func read(todoID: UUID) -> Single<Todo?> {
readTodoIDCallCount += 1
readTodoIDTodoID = todoID
return .just(readTodoIDTodo)
}

Check warning on line 32 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift#L28-L32

Added lines #L28 - L32 were not covered by tests

var readGreaterThanCallCount = 0
var readGreaterThanDate: Date?
var readGreaterThanTodo: [Todo] = []
func read(greaterThan date: Date) -> Single<[Todo]> {
readGreaterThanCallCount += 1
readGreaterThanDate = date
return .just(readGreaterThanTodo)
}

Check warning on line 41 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift#L37-L41

Added lines #L37 - L41 were not covered by tests

var readGreaterOrEqualThanLessThanCallCount = 0
var readGreaterOrEqualThanLessThanGreaterOrEqualDate: Date?
var readGreaterOrEqualThanLessThanLessDate: Date?
var readGreaterOrEqualThanLessThanTodos: [Todo] = []
func read(greaterOrEqualThan greaterOrEqualDate: Date, lessThan lessDate: Date) -> Single<[Todo]> {
readGreaterOrEqualThanLessThanCallCount += 1
readGreaterOrEqualThanLessThanGreaterOrEqualDate = greaterOrEqualDate
readGreaterOrEqualThanLessThanLessDate = lessDate
return .just(readGreaterOrEqualThanLessThanTodos)
}

var readKeywordCallCount = 0
var readKeywordKeyword: String?
var readKeywordTodos: [Todo] = []
func read(keyword: String) -> Single<[Todo]> {
readKeywordCallCount += 1
readKeywordKeyword = keyword
return .just(readKeywordTodos)
}

var updateTodoCallCount = 0
var updateTodoTodo: Todo?
func update(todo: Todo) -> Single<Void> {
updateTodoCallCount += 1
updateTodoTodo = todo
return .just(())
}

var deleteTodoCallCount = 0
var deleteTodoTodo: Todo?
func delete(todo: Todo) -> Single<Void> {
deleteTodoCallCount += 1
deleteTodoTodo = todo
return .just(())
}

Check warning on line 77 in InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift

View check run for this annotation

Codecov / codecov/patch

InMyMemory/Domain/Tests/UseCaseTests/Repositories/TodoRepositoryMock.swift#L73-L77

Added lines #L73 - L77 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// EmotionRecordUseCaseTests.swift
//
//
// Created by 홍성준 on 1/19/24.
//

@testable import UseCases
import Entities
import XCTest
import Quick
import Nimble

final class EmotionRecordUseCaseTests: QuickSpec {

override class func spec() {
var sut: EmotionRecordUseCase!
var repository: EmotionRepositoryMock!

describe("") {
beforeEach {
repository = .init()
sut = .init(emotionRepository: repository)
}

context("createEmotion이 호출되면") {
let emotion: Emotion = .init(id: .init(), note: "", emotionType: .good, date: .init())
beforeEach {
_ = sut.createEmotion(emotion)
}

it("EmotionRepository의 create(emotion: Emotion)이 호출된다") {
expect { repository.createEmotionEmotion?.id } == emotion.id
expect { repository.createEmotionCallCount } == 1
}
}
}
}

}
Loading