Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Article/network refactor #7

Merged
merged 34 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c825219
Update tuist version and Moya
ronan-ociosoig-edo Nov 29, 2021
ba31206
Remove unused mock, fix header names, fix warning related to deprecat…
ronan-ociosoig-edo Dec 31, 2021
f156748
Fix warnings in Haneke
ronan-ociosoig-edo Dec 31, 2021
1df0800
Fix the swift lint step for the MacBook M1 processor as HomeBrew uses…
ronan-ociosoig-edo Dec 31, 2021
401a0ac
Move files and rename module named in header
ronan-ociosoig-edo Jan 1, 2022
be1ff3a
Implement the Combine asynchronous request and update tests and examp…
ronan-ociosoig-edo Jan 1, 2022
6fcc080
Add URLProtocolMock and support in the unit test to read a mock file
ronan-ociosoig-edo Jan 2, 2022
0970c8b
Update module names in source header
ronan-ociosoig-edo Jan 3, 2022
27d81af
Replace template with basic test for the next identifier generator
ronan-ociosoig-edo Jan 3, 2022
53e4f05
Add test to validate HTTP 401 Invalid response error condition
ronan-ociosoig-edo Jan 3, 2022
6a6478e
Extend URLProtocolMock to use a response struct
ronan-ociosoig-edo Jan 4, 2022
6bf3d10
Update the README from master
ronanociosoig Jan 4, 2022
966e130
Fix import statements for Catch example app
ronan-ociosoig-edo Jan 4, 2022
84ff2e3
Fix swift lint warnings and errors
ronan-ociosoig-edo Jan 4, 2022
a2fb484
Remove spaces in scheme names
ronan-ociosoig-edo Jan 4, 2022
5b5c287
Formatting of the project manifest
ronan-ociosoig-edo Jan 4, 2022
e587076
Fix swift lint end of line warning
ronan-ociosoig-edo Jan 4, 2022
3b95dcf
Update Catch example app and Pokedex app search with Combine implemen…
ronan-ociosoig-edo Jan 4, 2022
10bb24b
Remove dependency on Moya and Result
ronan-ociosoig-edo Jan 4, 2022
675baa2
Add stubs in the search service for UI testing
ronan-ociosoig-edo Jan 5, 2022
004de45
Add support for async await in the search service
ronan-ociosoig-edo Jan 5, 2022
36d739b
Improve reliability of UI test by adding waitForExistance with a time…
ronan-ociosoig-edo Jan 5, 2022
da1e0f1
Move the async testing property to the configuration in the Common mo…
ronan-ociosoig-edo Jan 5, 2022
31a02e5
Fix swift lint paths when running tuist test Pokedex
ronan-ociosoig-edo Jan 5, 2022
e3203bd
Improve error naming and testing
ronan-ociosoig-edo Jan 5, 2022
f800211
Fix perform request function to use injected session instance
ronan-ociosoig-edo Jan 5, 2022
8fad2ce
Fix error in Backpack UI module where it was not loading the image as…
ronan-ociosoig-edo Jan 5, 2022
1a10396
Add UI test that uses the async network request
ronan-ociosoig-edo Jan 6, 2022
341e33c
Rename the custom scheme to AsyncNetworkTesting and pass in a launch …
ronan-ociosoig-edo Jan 6, 2022
008d745
Add returning mock data when UITesting is passed in the launch arguments
ronan-ociosoig-edo Jan 6, 2022
d7bb39f
Refactor the Pokedex app data provider to support both Combine and as…
ronan-ociosoig-edo Jan 6, 2022
68f2c28
Improve UI testing by disabling UIView animations and speed up the test
ronan-ociosoig-edo Jan 6, 2022
37b20e8
Update the README and images used in it
ronan-ociosoig-edo Jan 6, 2022
4911594
Merge branch 'master' into article/NetworkRefactor
ronanociosoig Jan 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 0 additions & 45 deletions .package.resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"object": {
"pins": [
{
"package": "Alamofire",
"repositoryURL": "https://github.com/Alamofire/Alamofire.git",
"state": {
"branch": null,
"revision": "f96b619bcb2383b43d898402283924b80e2c4bae",
"version": "5.4.3"
}
},
{
"package": "JGProgressHUD",
"repositoryURL": "https://github.com/JonasGessner/JGProgressHUD",
Expand All @@ -18,42 +9,6 @@
"revision": "78d7cd35f1d90ff74fd82e486f2cbe4b24be8cf9",
"version": "2.2.0"
}
},
{
"package": "Moya",
"repositoryURL": "https://github.com/Moya/Moya.git",
"state": {
"branch": null,
"revision": "b3e5a233e0d85fd4d69f561c80988590859c7dee",
"version": "14.0.0"
}
},
{
"package": "ReactiveSwift",
"repositoryURL": "https://github.com/Moya/ReactiveSwift.git",
"state": {
"branch": null,
"revision": "f195d82bb30e412e70446e2b4a77e1b514099e88",
"version": "6.1.0"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"state": {
"branch": null,
"revision": "12920a5c2595926efab9274d6003e29f503dbb66",
"version": "5.0.0"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "254617dd7fae0c45319ba5fbea435bf4d0e15b5d",
"version": "5.1.2"
}
}
]
},
Expand Down
1 change: 1 addition & 0 deletions .tuist-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.52.0
Binary file added AppTargets.drawio.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 24 additions & 30 deletions Features/Catch/Example/Sources/DataProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,33 @@ public protocol DataSearchProviding {
extension DataProvider: DataSearchProviding {
public func search(identifier: Int, networkService: SearchService) {
appData.pokemon = nil
let queue = DispatchQueue.main

networkService.search(identifier: identifier) { (data, errorMessage) in
let queue = DispatchQueue.main

if let errorMessage = errorMessage {
if errorMessage == Constants.Translations.Error.statusCode404 {
searchCancellable = networkService.search(identifier: identifier)
.receive(on: queue)
.sink(receiveCompletion: { completion in
switch completion {
case .failure(let error):
let errorMessage = "\(error.localizedDescription)"
os_log("Error: %s", log: Log.data, type: .error, errorMessage)
self.notifier?.dataReceived(errorMessage: errorMessage, on: queue)
return
case .finished:
print("All good")
}

os_log("Error message: %s", log: Log.network, type: .error, errorMessage)
self.notifier?.dataReceived(errorMessage: errorMessage, on: queue)
return
}

guard let data = data else {
os_log("Error message: %s", log: Log.network, type: .error, Constants.Translations.Error.noDataError)
self.notifier?.dataReceived(errorMessage: Constants.Translations.Error.noDataError, on: queue)
return
}

do {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let pokemon = try decoder.decode(Pokemon.self, from: data)
self.appData.pokemon = pokemon
self.notifier?.dataReceived(errorMessage: nil, on: queue)
os_log("Success: %s", log: Log.network, type: .default, "Loaded")
} catch {
let errorMessage = "\(error)"
os_log("Error: %s", log: Log.data, type: .error, errorMessage)
self.notifier?.dataReceived(errorMessage: errorMessage, on: queue)
}
}
}, receiveValue: { data in
do {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let pokemon = try decoder.decode(Pokemon.self, from: data)
self.appData.pokemon = pokemon
self.notifier?.dataReceived(errorMessage: nil, on: queue)
os_log("Success: %s", log: Log.network, type: .default, "Loaded")
} catch {
let errorMessage = "\(error.localizedDescription)"
os_log("Error: %s", log: Log.data, type: .error, errorMessage)
self.notifier?.dataReceived(errorMessage: errorMessage, on: queue)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import PokedexCommon
import Common

protocol HomeActions {
func catchButtonAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2021 Sonomos.com. All rights reserved.
//

import PokedexCommon
import Common

protocol HomeDataProvider {

Expand Down
2 changes: 1 addition & 1 deletion Features/Catch/Example/Tests/AppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ final class CatchTests: XCTestCase {
func test_twoPlusTwo_isFour() {
XCTAssertEqual(2+2, 4)
}
}
}
2 changes: 1 addition & 1 deletion Features/Catch/Tests/CatchUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ final class CatchUITests: XCTestCase {
func test_example() {
XCTAssertEqual("CatchUI", "CatchUI")
}
}
}
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/Actions.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Actions.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/AppData.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// AppData.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
23 changes: 8 additions & 15 deletions Features/Common/Sources/Core/Configuration.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Configuration.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/02/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand All @@ -11,28 +11,21 @@ import UIKit
public struct Configuration {

public static var uiTesting: Bool {

// We can use CommandLine.arguments for this as well.
let arguments = ProcessInfo.processInfo.arguments
let result = arguments.contains("UITesting")

if result == true {
// Speed up the animations in the app when running UI testing.

if let first = UIApplication.shared.windows.first {
first.layer.speed = 100
}
}

return result
return arguments.contains("UITesting")
}

public static var networkTesting: Bool {
let arguments = CommandLine.arguments
return arguments.contains("NetworkTesting")
}

public static var authenticationErrorTesting: Bool {
public static var searchErrorTesting: Bool {
return CommandLine.arguments.contains("Error_401")
}

public static var asyncTesting: Bool {
let arguments = ProcessInfo.processInfo.arguments
return arguments.contains("AsyncTesting")
}
}
4 changes: 3 additions & 1 deletion Features/Common/Sources/Core/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Constants.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down Expand Up @@ -59,6 +59,8 @@ public struct Constants {
public static let noDataError = "Error: No data received."
public static let noResultsFound = "No results were found for your search."
public static let statusCode404 = "404"
public static let notFound = "Error 401 Pokemon not found"
public static let asyncError = "Async Search failed"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/Coordinating.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Coordinating.swift
// PokedexCommon
// Common
//
// Created by Ronan O Ciosig on 19/5/21.
// Copyright © 2021 Sonomos. All rights reserved.
Expand Down
6 changes: 4 additions & 2 deletions Features/Common/Sources/Core/DataProvider.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
//
// DataProvider.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
//

import Foundation
import os.log
import Combine

public class DataProvider: DataProviding {
public let appData = AppData(storage: FileStorage())
public var notifier: Notifier?
public var searchCancellable: AnyCancellable?

public init(){
public init() {

}

Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/DataProviding.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// DataProviding.swift
// PokedexCommon
// Common
//
// Created by Ronan O Ciosig on 5/6/21.
// Copyright © 2021 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/Notifier.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Notifier.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Core/Updatable.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Updatable.swift
// PokedexCommon
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Extensions/Loadable.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Loadable.swift
// Pokedex
// Common
//
// Created by Ronan on 26/11/2018.
// Copyright © 2018 Sonomos. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// UIBarButtonItem+Extension.swift
// Pokedex
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// UITableViewCell+Extension.swift
// Pokedex
// Common
//
// Created by Ronan on 26/11/2018.
// Copyright © 2018 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Model/Generator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Generator.swift
// Pokedex
// Common
//
// Created by Ronan on 10/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Model/LocalPokemon.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Pokemon.swift
// Pokedex
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Model/Pokemon.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Pokemon.swift
// Pokedex
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Model/PokemonParser.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PokemonParser.swift
// Pokedex
// Common
//
// Created by Ronan on 10/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Model/ScreenPokemon.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// ScreenPokemon.swift
// Pokedex
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Util/FileStorage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// FileStorage.swift
// Pokedex
// Common
//
// Created by Ronan on 23/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Util/Storage.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Storage.swift
// Pokedex
// Common
//
// Created by Ronan on 10/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion Features/Common/Sources/Views/PokemonView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PokemonView.swift
// Pokedex
// Common
//
// Created by Ronan on 09/05/2019.
// Copyright © 2019 Sonomos. All rights reserved.
Expand Down