Skip to content

Commit

Permalink
Merge pull request #23 from joselinoneto/22-fix-tests
Browse files Browse the repository at this point in the history
fixing tests
  • Loading branch information
joselinoneto authored Sep 11, 2022
2 parents 9cae487 + 1a2eebd commit 95983c1
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:

runs-on: macos-latest
runs-on: macos-12

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 8 additions & 0 deletions .idea/ToolboxAPIClient.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions .idea/runConfigurations/ToolboxAPIClient_Package.xml

This file was deleted.

90 changes: 23 additions & 67 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ToolboxAPIClientTests"
BuildableName = "ToolboxAPIClientTests"
BlueprintName = "ToolboxAPIClientTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// swift-tools-version:5.3
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ToolboxAPIClient",
platforms: [.iOS(.v14), .watchOS(.v7)],
platforms: [.macOS(.v12), .iOS(.v15), .watchOS(.v8)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand Down
3 changes: 1 addition & 2 deletions Sources/ToolboxAPIClient/BaseNetworkWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import Combine

@available(iOS 15.0, *)
public class BaseNetworkWorker<T> where T: Codable {
private var targetType: TargetType

Expand Down Expand Up @@ -71,7 +70,7 @@ public class BaseNetworkWorker<T> where T: Codable {
let data = try? jsonEncoder.encode(httpBody)
urlRequest.httpBody = data
}

let (data, _) = try await URLSession.shared.data(for: urlRequest)
let decoder = JSONDecoder()
return try decoder.decode(T?.self, from: data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import ToolboxAPIClient

public class LoginManagerAPI: LoginRequestable {
public func login(email: String, password: String) async throws -> LoginDto? {
try await BaseNetworkWorker<LoginDto>(target: LoginTarget.login(email: email, password: password)).urlRequest()
let login: LoginDto = LoginDto(email: email, password: password, token: nil)
return try await BaseNetworkWorker<LoginDto>(target: LoginTarget.login).urlRequest(contentBody: login)
}

public func createUser(email: String, password: String) async throws -> LoginDto? {
Expand All @@ -21,8 +22,4 @@ public class LoginManagerAPI: LoginRequestable {
public func me() async throws -> UserDto? {
try await BaseNetworkWorker<UserDto>(target: LoginTarget.me).urlRequest()
}

public init() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol LoginRequestable {

public enum LoginTarget {
case createUser
case login(email: String, password: String)
case login
case me
}

Expand All @@ -36,7 +36,7 @@ extension LoginTarget: TargetType {
switch self {
case .createUser:
return "create"
case .login(_, _):
case .login:
return "login"
case .me:
return "me"
Expand All @@ -47,14 +47,20 @@ extension LoginTarget: TargetType {
switch self {
case .createUser:
return .post
case .login(_, _):
case .login:
return .post
case .me:
return .get
}
}

public var headers: [String : String]? {
nil
// Bad pratice! Basic Unit Testing.
// Must use Keychain
let defaults = UserDefaults.standard
if let token = defaults.string(forKey: "token") {
return ["Authorization": "Bearer \(token)"]
}
return nil
}
}
Loading

0 comments on commit 95983c1

Please sign in to comment.