generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from Team-Ampersand/59-current-user-role-use-case
🔀 :: 현재 유저의 권한 가져오는 도메인 로직 추가
- Loading branch information
Showing
22 changed files
with
291 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Projects/Domain/UserDomain/Interface/DataSource/LocalUserDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol LocalUserDataSource { | ||
func loadCurrentUserRole() throws -> UserRoleType | ||
} |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
Projects/Domain/UserDomain/Interface/Error/UserDomainError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
public enum UserDomainError: Error { | ||
// MARK: LoadCurrentUserRole | ||
case cannotFindUserRole | ||
} |
5 changes: 5 additions & 0 deletions
5
Projects/Domain/UserDomain/Interface/Repository/UserRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol UserRepository { | ||
func loadCurrentUserRole() throws -> UserRoleType | ||
} |
5 changes: 5 additions & 0 deletions
5
Projects/Domain/UserDomain/Interface/UseCase/LoadCurrentUserRoleUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol LoadCurrentUserRoleUseCase { | ||
func callAsFunction() throws -> UserRoleType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Projects/Domain/UserDomain/Sources/Assembly/UserDomainAssembly.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import KeyValueStoreInterface | ||
import Swinject | ||
import UserDomainInterface | ||
|
||
public final class UserDomainAssembly: Assembly { | ||
public init() {} | ||
public func assemble(container: Container) { | ||
container.register(LocalUserDataSource.self) { resolver in | ||
LocalUserDataSourceImpl(keyValueStore: resolver.resolve(KeyValueStore.self)!) | ||
} | ||
.inObjectScope(.container) | ||
|
||
container.register(UserRepository.self) { resolver in | ||
UserRepositoryImpl(localUserDataSource: resolver.resolve(LocalUserDataSource.self)!) | ||
} | ||
.inObjectScope(.container) | ||
|
||
container.register(LoadCurrentUserRoleUseCase.self) { resolver in | ||
LoadCurrentUserRoleUseCaseImpl(userRepository: resolver.resolve(UserRepository.self)!) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Projects/Domain/UserDomain/Sources/DataSource/LocalUserDataSourceImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
import KeyValueStoreInterface | ||
import UserDomainInterface | ||
|
||
final class LocalUserDataSourceImpl: LocalUserDataSource { | ||
private let keyValueStore: any KeyValueStore | ||
|
||
init(keyValueStore: any KeyValueStore) { | ||
self.keyValueStore = keyValueStore | ||
} | ||
|
||
func loadCurrentUserRole() throws -> UserRoleType { | ||
guard let userRoleString = keyValueStore.load(key: .userRole) as? String, | ||
let userRole = UserRoleType(rawValue: userRoleString) | ||
else { | ||
throw UserDomainError.cannotFindUserRole | ||
} | ||
return userRole | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Projects/Domain/UserDomain/Sources/Error/UserDomainErrorDescription.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import Localization | ||
import UserDomainInterface | ||
|
||
extension UserDomainError: LocalizedError { | ||
public var errorDescription: String? { | ||
switch self { | ||
case .cannotFindUserRole: | ||
return "Cannot find user role" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Projects/Domain/UserDomain/Sources/Repository/UserRepositoryImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
import UserDomainInterface | ||
|
||
final class UserRepositoryImpl: UserRepository { | ||
private let localUserDataSource: any LocalUserDataSource | ||
|
||
init(localUserDataSource: any LocalUserDataSource) { | ||
self.localUserDataSource = localUserDataSource | ||
} | ||
|
||
func loadCurrentUserRole() throws -> UserRoleType { | ||
try localUserDataSource.loadCurrentUserRole() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
Projects/Domain/UserDomain/Sources/UseCase/LoadCurrentUserRoleUseCaseImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
import UserDomainInterface | ||
|
||
struct LoadCurrentUserRoleUseCaseImpl: LoadCurrentUserRoleUseCase { | ||
private let userRepository: any UserRepository | ||
|
||
init(userRepository: any UserRepository){ | ||
self.userRepository = userRepository | ||
} | ||
|
||
func callAsFunction() throws -> UserRoleType { | ||
try userRepository.loadCurrentUserRole() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Projects/Domain/UserDomain/Testing/DataSource/LocalUserDataSourceSpy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
import UserDomainInterface | ||
|
||
final class LocalUserDataSourceSpy: LocalUserDataSource { | ||
var loadCurrentUserRoleCallCount = 0 | ||
var loadCurrentUserRoleReturn: UserRoleType = .member | ||
func loadCurrentUserRole() throws -> UserRoleType { | ||
loadCurrentUserRoleCallCount += 1 | ||
return loadCurrentUserRoleReturn | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Projects/Domain/UserDomain/Testing/Repository/UserRepositorySpy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
import UserDomainInterface | ||
|
||
final class UserRepositorySpy: UserRepository { | ||
var loadCurrentUserRoleCallCount = 0 | ||
var loadCurrentUserRoleReturn: UserRoleType = .member | ||
func loadCurrentUserRole() throws -> UserRoleType { | ||
loadCurrentUserRoleCallCount += 1 | ||
return loadCurrentUserRoleReturn | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Projects/Domain/UserDomain/Testing/UseCase/LoadCurrentUserRoleUseCaseSpy.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import UserDomainInterface | ||
|
||
final class LoadCurrentUserRoleUseCaseSpy: LoadCurrentUserRoleUseCase { | ||
var loadCurrentUserRoleCallCount = 0 | ||
var loadCurrentUserRoleReturn: UserRoleType = .member | ||
func callAsFunction() throws -> UserRoleType { | ||
loadCurrentUserRoleCallCount += 1 | ||
return loadCurrentUserRoleReturn | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Projects/Domain/UserDomain/Tests/LoadCurrentUserRoleUseCaseTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import XCTest | ||
@testable import UserDomainTesting | ||
@testable import UserDomain | ||
|
||
class LoadCurrentUserRoleUseCaseTests: XCTestCase { | ||
var loadCurrentUserRoleUseCase: LoadCurrentUserRoleUseCaseImpl! | ||
var userRepositorySpy: UserRepositorySpy! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
userRepositorySpy = UserRepositorySpy() | ||
loadCurrentUserRoleUseCase = LoadCurrentUserRoleUseCaseImpl(userRepository: userRepositorySpy) | ||
} | ||
|
||
override func tearDown() { | ||
loadCurrentUserRoleUseCase = nil | ||
userRepositorySpy = nil | ||
super.tearDown() | ||
} | ||
|
||
func testCallAsFunction() { | ||
// Given | ||
userRepositorySpy.loadCurrentUserRoleReturn = .member | ||
|
||
// When | ||
do { | ||
let currentUserRole = try loadCurrentUserRoleUseCase() | ||
|
||
// Then | ||
XCTAssertEqual( | ||
userRepositorySpy.loadCurrentUserRoleCallCount, | ||
1, | ||
"loadCurrentUserRole should be called once" | ||
) | ||
XCTAssertEqual( | ||
currentUserRole, | ||
.member, | ||
"The returned currentUserRole should be .admin" | ||
) | ||
} catch { | ||
XCTFail("Unexpected error thrown: \(error)") | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Projects/Domain/UserDomain/Tests/LocalUserDataSourceTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import UserDomainInterface | ||
import XCTest | ||
@testable import UserDomainTesting | ||
@testable import UserDomain | ||
@testable import KeyValueStoreTesting | ||
|
||
final class LocalUserDataSourceTests: XCTestCase { | ||
var localUserDataSource: LocalUserDataSourceImpl! | ||
var keyValueStoreFake: DictionaryKeyValueStore! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
keyValueStoreFake = DictionaryKeyValueStore() | ||
localUserDataSource = LocalUserDataSourceImpl(keyValueStore: keyValueStoreFake) | ||
} | ||
|
||
override func tearDown() { | ||
localUserDataSource = nil | ||
keyValueStoreFake = nil | ||
super.tearDown() | ||
} | ||
|
||
func testLoadCurrentUserRole_Success() { | ||
// Given | ||
keyValueStoreFake.save(key: .userRole, value: UserRoleType.member.rawValue) | ||
|
||
// When | ||
do { | ||
let currentUserRole = try localUserDataSource.loadCurrentUserRole() | ||
|
||
// Then | ||
XCTAssertEqual( | ||
currentUserRole, | ||
.member, | ||
"The returned currentUserRole should be .admin" | ||
) | ||
} catch { | ||
XCTFail("Unexpected error thrown: \(error)") | ||
} | ||
} | ||
|
||
func testLoadCurrentUserRole_ThrowsError() { | ||
// When | ||
do { | ||
_ = try localUserDataSource.loadCurrentUserRole() | ||
|
||
// Then | ||
XCTFail("Expected error UserDomainError.cannotFindUserRole not thrown") | ||
} catch { | ||
// Then | ||
XCTAssertEqual( | ||
error as? UserDomainError, | ||
UserDomainError.cannotFindUserRole, | ||
"Unexpected error type" | ||
) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import XCTest | ||
@testable import UserDomainTesting | ||
@testable import UserDomain | ||
|
||
final class UserRepositoryTests: XCTestCase { | ||
var userRepository: UserRepositoryImpl! | ||
var localUserDataSourceSpy: LocalUserDataSourceSpy! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
localUserDataSourceSpy = LocalUserDataSourceSpy() | ||
userRepository = UserRepositoryImpl(localUserDataSource: localUserDataSourceSpy) | ||
} | ||
|
||
override func tearDown() { | ||
userRepository = nil | ||
localUserDataSourceSpy = nil | ||
super.tearDown() | ||
} | ||
|
||
func testLoadCurrentUserRole() { | ||
// Given | ||
localUserDataSourceSpy.loadCurrentUserRoleReturn = .member | ||
|
||
// When | ||
do { | ||
let currentUserRole = try userRepository.loadCurrentUserRole() | ||
|
||
// Then | ||
XCTAssertEqual( | ||
localUserDataSourceSpy.loadCurrentUserRoleCallCount, | ||
1, | ||
"loadCurrentUserRole should be called once" | ||
) | ||
XCTAssertEqual( | ||
currentUserRole, | ||
.member, | ||
"The returned currentUserRole should be .member" | ||
) | ||
} catch { | ||
XCTFail("Unexpected error thrown: \(error)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters