-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
Heim/DataModule/DataModuleTests/RepositoryTests/DiaryRepositoryTests.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,126 @@ | ||
// | ||
// DiaryRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class DiaryRepositoryTests: XCTestCase { | ||
var sut: DiaryRepository! | ||
var mockDataStorage = MockDataStorage() | ||
|
||
override func setUp() { | ||
sut = DefaultDiaryRepository(dataStorage: mockDataStorage) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockDataStorage = .init() | ||
} | ||
|
||
func test_read_diaries_through_readDiaries() async throws { | ||
// Given | ||
let input = CalendarDate( | ||
year: 2024, | ||
month: 12, | ||
day: 5, | ||
hour: 1, | ||
minute: 2, | ||
second: 3 | ||
) | ||
|
||
let mockDiary = Diary( | ||
calendarDate: input, | ||
emotion: Emotion.angry, | ||
emotionReport: EmotionReport(text: ""), | ||
voice: Voice(audioBuffer: Data()), | ||
summary: Summary(text: "") | ||
) | ||
|
||
// When | ||
mockDataStorage.returnValue.readData = [mockDiary] | ||
let output = try await sut.readDiaries(calendarDate: input) | ||
|
||
// Then | ||
XCTAssertEqual(output, [mockDiary]) | ||
} | ||
|
||
func test_delete_diary_successfully_without_error() async throws { | ||
// Given | ||
let input = CalendarDate( | ||
year: 2024, | ||
month: 12, | ||
day: 5, | ||
hour: 1, | ||
minute: 2, | ||
second: 3 | ||
) | ||
|
||
// When | ||
do { | ||
try await sut.deleteDiary(calendarDate: input) | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 위치") | ||
} | ||
} | ||
|
||
func test_read_all_diaries_through_readTotalDiaries() async throws { | ||
// Given | ||
let mockDiary = Diary( | ||
calendarDate: CalendarDate( | ||
year: 2024, | ||
month: 12, | ||
day: 5, | ||
hour: 1, | ||
minute: 2, | ||
second: 3 | ||
), | ||
emotion: Emotion.angry, | ||
emotionReport: EmotionReport(text: ""), | ||
voice: Voice(audioBuffer: Data()), | ||
summary: Summary(text: "") | ||
) | ||
|
||
// When | ||
mockDataStorage.returnValue.readAll = [mockDiary] | ||
let output = try await sut.readTotalDiaries() | ||
|
||
// Then | ||
XCTAssertEqual(output, [mockDiary]) | ||
} | ||
|
||
func test_save_diary_successfully_without_error() async throws { | ||
// Given | ||
let input = Diary( | ||
calendarDate: CalendarDate( | ||
year: 2024, | ||
month: 12, | ||
day: 5, | ||
hour: 1, | ||
minute: 2, | ||
second: 3 | ||
), | ||
emotion: Emotion.angry, | ||
emotionReport: EmotionReport(text: ""), | ||
voice: Voice(audioBuffer: Data()), | ||
summary: Summary(text: "") | ||
) | ||
|
||
// When | ||
do { | ||
try await sut.saveDiary(data: input) | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 위치") | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Heim/DataModule/DataModuleTests/RepositoryTests/GenerativeAIRepositoryTests.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,51 @@ | ||
// | ||
// GenerativeAIRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/6/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class GenerativeAIRepositoryTests: XCTestCase { | ||
var sut: GenerativeAIRepository! | ||
var mockNetworkProvider = MockNetworkProvider() | ||
|
||
override func setUp() { | ||
sut = GeminiGenerativeAIRepository(networkProvider: mockNetworkProvider) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockNetworkProvider = .init() | ||
} | ||
|
||
func test_generate_content_through_generateContent() async throws { | ||
// Given | ||
let input = "TESTPROMPT" | ||
let mockDTO = GeminiGenerateResponseDTO( | ||
candidates: [Candidate( | ||
content: ResponseContent( | ||
parts: [ResponsePart(text: input)], | ||
role: "" | ||
), | ||
finishReason: "" | ||
)], | ||
usageMetadata: UsageMetadata( | ||
promptTokenCount: 0, | ||
candidatesTokenCount: 0, | ||
totalTokenCount: 0 | ||
), | ||
modelVersion: "" | ||
) | ||
|
||
// When | ||
mockNetworkProvider.returnValue.request = mockDTO | ||
let output = try await sut.generateContent(for: "") | ||
|
||
// Then | ||
XCTAssertEqual(output, input) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Heim/DataModule/DataModuleTests/RepositoryTests/SettingRepositoryTests.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,52 @@ | ||
// | ||
// SettingRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class SettingRepositoryTests: XCTestCase { | ||
var sut: SettingRepository! | ||
var mockDataStorage = MockDataStorage() | ||
|
||
override func setUp() { | ||
sut = DefaultSettingRepository(localStorage: mockDataStorage) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockDataStorage = .init() | ||
} | ||
|
||
func test_remove_cache_successfully_without_error() async throws { | ||
// Given | ||
|
||
// When | ||
do { | ||
try await sut.removeCacheData() | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 자리") | ||
} | ||
} | ||
|
||
func test_reset_data_successfully_without_error() async throws { | ||
// Given | ||
|
||
// When | ||
do { | ||
try await sut.resetData() | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 자리") | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Heim/DataModule/DataModuleTests/RepositoryTests/SpotifyOAuthRepositoryTests.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,75 @@ | ||
// | ||
// SpotifyOAuthRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class SpotifyOAuthRepositoryTests: XCTestCase { | ||
var sut: SpotifyOAuthRepository! | ||
var mockNetworkProvider = MockNetworkProvider() | ||
var mockTokenManager = MockTokenManager() | ||
|
||
override func setUp() { | ||
sut = DefaultSpotifyOAuthRepository( | ||
networkProvider: mockNetworkProvider, | ||
tokenManager: mockTokenManager | ||
) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockNetworkProvider = .init() | ||
mockTokenManager = .init() | ||
} | ||
|
||
func test_create_authoriztion_url_through_createAuthorizationURL() throws { | ||
// Given | ||
let input = "http://testheim.kr" | ||
let challenge = "TESTChallenge" | ||
let mockURL = try mockNetworkProvider.makeURL( | ||
target: MockRequestTarget( | ||
baseURL: input, | ||
path: "", | ||
method: .get, | ||
headers: [:], | ||
query: [:] | ||
) | ||
) | ||
|
||
// When | ||
mockNetworkProvider.returnValue.makeURL = mockURL | ||
let output = try sut.createAuthorizationURL(codeChallenge: challenge) | ||
|
||
// Then | ||
XCTAssertEqual(output, mockURL) | ||
} | ||
|
||
func test_create_access_token_through_exchangeAccessToken() async throws { | ||
// Given | ||
let input = "TESTCode" | ||
let verifier = "TESTVerifier" | ||
let mockDTO = SpotifyAccessTokenResponseDTO( | ||
accessToken: "", | ||
tokenType: "", | ||
scope: "", | ||
expiresIn: 0, | ||
refreshToken: "" | ||
) | ||
|
||
// When | ||
do { | ||
mockNetworkProvider.returnValue.request = mockDTO | ||
try await sut.exchangeAccessToken(with: input, codeVerifier: verifier) | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 자리") | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
Heim/DataModule/DataModuleTests/RepositoryTests/SpotifyRepositoryTests.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,37 @@ | ||
// | ||
// SpotifyRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class SpotifyRepositoryTests: XCTestCase { | ||
var sut: SpotifyRepository! | ||
var mockNetworkProvider = MockNetworkProvider() | ||
|
||
override func setUp() { | ||
sut = DefaultSpotifyRepository(networkProvider: mockNetworkProvider) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockNetworkProvider = .init() | ||
} | ||
|
||
func test_fetch_recommend_tracks_through_fetchRecommendationTrack() async throws { | ||
// Given | ||
let input = Emotion.angry | ||
let mockDTO = SpotifyRecommendResponseDTO(tracks: [], seeds: []) | ||
|
||
// When | ||
mockNetworkProvider.returnValue.request = mockDTO | ||
let output = try await sut.fetchRecommendationTrack(input) | ||
|
||
// Then | ||
XCTAssertEqual(output, []) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Heim/DataModule/DataModuleTests/RepositoryTests/UserRepositoryTests.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,51 @@ | ||
// | ||
// UserRepositoryTests.swift | ||
// DataModuleTests | ||
// | ||
// Created by 정지용 on 12/5/24. | ||
// | ||
|
||
import XCTest | ||
@testable import DataModule | ||
@testable import Domain | ||
|
||
final class UserRepositoryTests: XCTestCase { | ||
var sut: UserRepository! | ||
var mockDataStorage = MockDataStorage() | ||
|
||
override func setUp() { | ||
sut = DefaultUserRepository(dataStorage: mockDataStorage) | ||
} | ||
|
||
override func tearDown() { | ||
sut = nil | ||
mockDataStorage = .init() | ||
} | ||
|
||
func test_fetch_username_through_fetchUserName() async throws { | ||
// Given | ||
let input = "TEST" | ||
|
||
// When | ||
mockDataStorage.returnValue.readData = input | ||
let output = try await sut.fetchUsername() | ||
|
||
// Then | ||
XCTAssertEqual(output, input) | ||
} | ||
|
||
func test_update_username_successfully_without_error() async throws { | ||
// Given | ||
let input = "TEST" | ||
|
||
// When | ||
do { | ||
try await sut.updateUsername(to: input) | ||
|
||
// Then | ||
XCTAssert(true) | ||
} catch { | ||
XCTFail("성공해야 하는 자리") | ||
} | ||
} | ||
} |