Skip to content

Commit

Permalink
Merge pull request #213 from YAPP-Github/Test/#212
Browse files Browse the repository at this point in the history
Test/#212 DTO Tests
  • Loading branch information
anyukyung authored Feb 23, 2023
2 parents 18e3767 + d9db4c8 commit 9fbb5e6
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 289 deletions.
199 changes: 60 additions & 139 deletions RefillStation/RefillStation.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion RefillStation/RefillStation/Data/DTOs/User/UserDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension UserDTO {
id: id ?? 0,
name: nickname ?? "",
imageURL: imgPath,
level: UserLevelInfo(level: UserLevelInfo.Level(rawValue: rating ?? 0) ?? .beginner)
level: UserLevelInfo(level: UserLevelInfo.Level(rawValue: rating ?? 0) ?? .regular)
)
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// LoginDTOTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/22.
//

import XCTest
@testable import RefillStation

final class LoginDTOTests: XCTestCase {
var fullContentUnit: LoginDTO!
var minimumContentUnit: LoginDTO!

override func setUpWithError() throws {
fullContentUnit = LoginDTO(name: "name", email: "email", imgPath: "imgPath", oauthType: "oauthType", oauthIdentity: "oauthIdentity", jwt: "jwt", refreshToken: "refreshToken")
minimumContentUnit = LoginDTO(name: nil, email: nil, imgPath: nil, oauthType: nil, oauthIdentity: nil, jwt: nil, refreshToken: nil)
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_LoginDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_OAuthLoginResponseValue를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toDomain()
// then
let expectationResult = OAuthLoginResponseValue(name: "name", email: "email", imgPath: "imgPath", oauthIdentity: "oauthIdentity", oauthType: "oauthType", jwt: "jwt", refreshToken: "refreshToken")
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_LoginDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_OAuthLoginResponseValue를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toDomain()
// then
let expectationResult = OAuthLoginResponseValue(name: nil, email: nil, imgPath: nil, oauthIdentity: "", oauthType: "", jwt: nil, refreshToken: "")
XCTAssertEqual(domainResult, expectationResult)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// FetchStoreRecommendTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/23.
//

import XCTest
@testable import RefillStation

final class FetchStoreRecommendDTOTests: XCTestCase {
var fullContentUnit: FetchStoreRecommendDTO!
var minimumContentUnit: FetchStoreRecommendDTO!

override func setUpWithError() throws {
fullContentUnit = FetchStoreRecommendDTO(recommendation: true, count: 10)

minimumContentUnit = FetchStoreRecommendDTO(recommendation: nil, count: nil)
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_FetchStoreRecommendDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_FetchStoreRecommendResponseValue를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toResponseValue()
// then
let expectationResult = FetchStoreRecommendResponseValue(recommendCount: 10, didRecommended: true)
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_FetchStoreRecommendDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_FetchStoreRecommendResponseValue를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toResponseValue()
// then
let expectationResult = FetchStoreRecommendResponseValue(recommendCount: 0, didRecommended: false)
XCTAssertEqual(domainResult, expectationResult)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// ProductDTOTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/23.
//

import XCTest
@testable import RefillStation

final class ProductDTOTests: XCTestCase {
var fullContentUnit: ProductDTO!
var minimumContentUnit: ProductDTO!

override func setUpWithError() throws {
fullContentUnit = ProductDTO(createdAt: "", modifiedAt: "", id: 0, storeId: 0, title: "title", price: 10, unit: "mg", brand: "brand", category: "샴푸", imgPath: "imgPath", isHided: true, isReady: true)

minimumContentUnit = ProductDTO(createdAt: nil, modifiedAt: nil, id: nil, storeId: nil, title: nil, price: nil, unit: nil, brand: nil, category: nil, imgPath: nil, isHided: nil, isReady: nil)
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_ProductDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_Product를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toDomain()
// then
let expectationResult = Product(name: "title", brand: "brand", measurement: "mg", price: 10, imageURL: "imgPath", category: .init(title: "샴푸"))
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_ProductDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_Product를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toDomain()
// then
let expectationResult = Product(name: "", brand: "", measurement: "", price: 0, imageURL: "", category: .init(title: ""))
XCTAssertEqual(domainResult, expectationResult)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// ReviewDTOTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/23.
//

import XCTest
@testable import RefillStation

final class ReviewDTOTests: XCTestCase {
var fullContentUnit: ReviewDTO!
var minimumContentUnit: ReviewDTO!

override func setUpWithError() throws {
fullContentUnit = ReviewDTO(id: 1, storeId: 1, userId: 1, reviewText: "reviewText", createdAt: "2023-01-29T18:56:24", modifiedAt: "modifiedAt", user: .init(createdAt: "createdAt", modifiedAt: "modifiedAt", id: 1, name: "name", nickname: "nickname", email: "email", phoneNumber: "phoneNumber", type: "type", oauthType: "oauthType", oauthIdentity: "oauthIdentity", rating: 1, imgPath: "imgPath", removedAt: "removedAt"), imgReviews: [.init(createdAt: "createdAt", modifiedAt: "modifiedAt", id: 1, reviewId: 1, path: "path")], reviewTagLogs: [.init(createdAt: "createdAt", modifiedAt: "modifiedAt", id: 1, reviewId: 1, userId: 1, storeId: 1, reviewTagId: -1), .init(createdAt: "createdAt", modifiedAt: "modifiedAt", id: 1, reviewId: 1, userId: 1, storeId: 1, reviewTagId: nil)])

minimumContentUnit = ReviewDTO(id: nil, storeId: nil, userId: nil, reviewText: nil, createdAt: "2023-01-29T18:56:24", modifiedAt: nil, user: nil, imgReviews: nil, reviewTagLogs: nil)
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_ReviewDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_Review를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toDomain()
// then
let expectationResult = Review(userId: 1, userNickname: "nickname", profileImagePath: "imgPath", writtenDate: "2023-01-29T18:56:24".toDate()!, imageURL: ["path"], description: "reviewText", tags: [.noKeywordToChoose, .noKeywordToChoose])
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_ReviewDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_Review를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toDomain()
// then
let expectationResult = Review(userId: 0, userNickname: "", profileImagePath: "", writtenDate: "2023-01-29T18:56:24".toDate()!, imageURL: [], description: "", tags: [])
XCTAssertEqual(domainResult, expectationResult)
}
}

fileprivate extension String {
func toDate() -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" // "2023-02-07T14:22:26"
let dateString = dateFormatter.date(from: self)
return dateString
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// StoreDTOTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/23.
//

import XCTest
@testable import RefillStation

final class StoreDTOTests: XCTestCase {
var fullContentUnit: StoreDTO!
var minimumContentUnit: StoreDTO!

override func setUpWithError() throws {
fullContentUnit = StoreDTO(id: 0, userId: 0, name: "name", status: "", longitude: "", latitude: "", businessHour: [.init(day: "월월", time: "test time")], notice: "", address: "address", instaAccount: "instaAccount", callNumber: "", registrationNumber: "", isReady: true, distance: "10", imgStores: [.init(id: 0, storeId: 0, path: "")], storeRefillGuides: [.init(createdAt: "", modifiedAt: "", id: 0, storeId: 0, imgPath: "", removedAt: "")])

minimumContentUnit = StoreDTO(id: nil, userId: nil, name: nil, status: nil, longitude: nil, latitude: nil, businessHour: nil, notice: nil, address: nil, instaAccount: nil, callNumber: nil, registrationNumber: nil, isReady: nil, distance: nil, imgStores: [], storeRefillGuides: [])
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_StoreDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_Store를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toDomain()
// then
let expectationResult = Store(storeId: 0, name: "name", address: "address", distance: 10, phoneNumber: "", snsAddress: "instaAccount", didUserRecommended: false, recommendedCount: 0, imageURL: [""], businessHour: [.init(day: .mon, time: "test time")], notice: "", storeRefillGuideImagePaths: [""])
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_StoreDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_Store를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toDomain()
// then
let expectationResult = Store(storeId: 0, name: "", address: "", distance: 0, phoneNumber: "", snsAddress: "", didUserRecommended: false, recommendedCount: 0, imageURL: [], businessHour: [], notice: "", storeRefillGuideImagePaths: [])
XCTAssertEqual(domainResult, expectationResult)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// StoreRecommendDTOTests.swift
// RefillStationTests
//
// Created by 천수현 on 2023/02/23.
//

import XCTest
@testable import RefillStation

final class StoreRecommendDTOTests: XCTestCase {
var fullContentUnit: StoreRecommendDTO!
var minimumContentUnit: StoreRecommendDTO!

override func setUpWithError() throws {
fullContentUnit = StoreRecommendDTO(isRecommendation: true, count: 10)

minimumContentUnit = StoreRecommendDTO(isRecommendation: nil, count: nil)
}

override func tearDownWithError() throws {
fullContentUnit = nil
minimumContentUnit = nil
}

func test_모든_필드가_채워진_StoreRecommendDTO의_toDomain_메서드를_호출하면_모든_필드가_채워진_RecommendStoreResponseValue를_반환하는지() {
// given
// when
let domainResult = fullContentUnit.toResponseValue()
// then
let expectationResult = RecommendStoreResponseValue(recommendCount: 10, didRecommended: true)
XCTAssertEqual(domainResult, expectationResult)
}

func test_최소한의_필드만_채워진_StoreRecommendDTO의_toDomain_메서드를_호출하면_기본값으로_채워진_RecommendStoreResponseValue를_반환하는지() {
// given
// when
let domainResult = minimumContentUnit.toResponseValue()
// then
let expectationResult = RecommendStoreResponseValue(recommendCount: 0, didRecommended: false)
XCTAssertEqual(domainResult, expectationResult)
}
}
Loading

0 comments on commit 9fbb5e6

Please sign in to comment.