Skip to content
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
2 changes: 1 addition & 1 deletion GitExplorerTests/MockService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import XCTest
import Combine
@testable import GitExplorer

class Mock: ServiceProtocol {
class MockService: ServiceProtocol {

var isSuccess: Bool = true

Expand Down
25 changes: 3 additions & 22 deletions GitExplorerTests/RepositoriesViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,13 @@ import XCTest
import Combine
@testable import GitExplorer

class MockServiceRepositories: ServiceProtocol {
var isSuccess: Bool = true

func getUser(with username: String) async throws -> User {
return User(login: "", avatarUrl: "", url: "", htmlURL: "", publicRepos: 0, publicGists: 0, followers: 0, following: 0, createdAt: Date())
}

func getRepos(with username: String) async throws -> [Repo] {
if isSuccess {
return [
Repo(name: "FirstRepo", repoDescription: nil, createdAt: Date(), updatedAt: Date(), stargazersCount: 4, forksCount: 3),
Repo(name: "SecondRepo", repoDescription: nil, createdAt: Date(), updatedAt: Date(), stargazersCount: 2, forksCount: 1)
]
} else {
throw DSError.reposFailed
}
}
}

final class RepositoriesViewModelTests: XCTestCase {

private var cancellables = Set<AnyCancellable>()

//MARK: TESTS SUCCESS
func testWhenGetReposIsCalledWithSuccessShouldReturnRepos() async throws {
let mockService = MockServiceRepositories()
let mockService = MockService()

let user = User(login: "Diggo", avatarUrl: "", url: "", htmlURL: "", publicRepos: 4, publicGists: 3, followers: 2, following: 1, createdAt: Date())

Expand All @@ -60,7 +41,7 @@ final class RepositoriesViewModelTests: XCTestCase {
}

func testWhenGetReposIsCalledWithFailureDueToEmptyLoginShouldReturnEmptyArray() async throws {
let mockService = MockServiceRepositories()
let mockService = MockService()

let user = User(login: "", avatarUrl: "", url: "", htmlURL: "", publicRepos: 0, publicGists: 0, followers: 0, following: 0, createdAt: Date())

Expand All @@ -85,7 +66,7 @@ final class RepositoriesViewModelTests: XCTestCase {

//MARK: TESTS FAILURE
func testWhenGetReposIsCalledWithSuccessAndThenFailShouldReturnEmptyArray() async throws {
let mockService = MockServiceRepositories()
let mockService = MockService()
mockService.isSuccess = false

let user = User(login: "Diggo", avatarUrl: "", url: "", htmlURL: "", publicRepos: 0, publicGists: 0, followers: 0, following: 0, createdAt: Date())
Expand Down
14 changes: 0 additions & 14 deletions GitExplorerTests/SearchViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ import XCTest
import Combine
@testable import GitExplorer

class MockService: ServiceProtocol {
var isSuccess: Bool = true

func getUser(with username: String) async throws -> User {
if isSuccess {
return User(login: username, avatarUrl: "", url: "", htmlURL: "", publicRepos: 4, publicGists: 3, followers: 2, following: 1, createdAt: Date())
} else {
throw DSError.invalidUsername
}
}

func getRepos(with username: String) async throws -> [Repo] { return [] }
}

final class GitExplorerTests: XCTestCase {

private var cancellables = Set<AnyCancellable>()
Expand Down