Skip to content

Commit

Permalink
[Test] #181 - Add RepositoryTests
Browse files Browse the repository at this point in the history
  • Loading branch information
clxxrlove committed Dec 5, 2024
1 parent 7bd2558 commit d5d1a7c
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 0 deletions.
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("성공해야 하는 위치")
}
}
}
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)
}
}
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("성공해야 하는 자리")
}
}
}
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("성공해야 하는 자리")
}
}
}
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, [])
}
}
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("성공해야 하는 자리")
}
}
}

0 comments on commit d5d1a7c

Please sign in to comment.