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

Account Info #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 Books/Books/AccountView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct AccountView : View {
@ObservedObject var authenticationViewModel: AuthenticationViewModel
@Environment(\.presentationMode) var presentationMode
var body: some View {
return VStack {
VStack {
Button(action: {
self.presentationMode.wrappedValue.dismiss()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.34) {
Expand Down
11 changes: 6 additions & 5 deletions Books/Books/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import Combine
struct ContentView : View {
@ObservedObject var authenticationViewModel: AuthenticationViewModel
var body: some View {
view(for: authenticationViewModel.authenticated).onAppear() {
self.authenticationViewModel.attemptAutomaticAuthentication()
}
view(for: authenticationViewModel.state)
.onAppear() {
self.authenticationViewModel.attemptAutomaticAuthentication()
}
}

func view(for state: AuthenticationState) -> AnyView {
Expand Down Expand Up @@ -51,7 +52,7 @@ struct ContentView : View {
}

func signInView() -> some View {
return SignInView(authentication: authenticationViewModel)
SignInView(authentication: authenticationViewModel)
}
}

Expand All @@ -61,7 +62,7 @@ struct ActivityIndicator: UIViewRepresentable {
let style: UIActivityIndicatorView.Style

func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
return UIActivityIndicatorView(style: style)
UIActivityIndicatorView(style: style)
}

func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>) {
Expand Down
4 changes: 2 additions & 2 deletions Books/Books/LoanRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct LoanRow : View {
var loanViewModel: LoanViewModel

var body: some View {
return VStack {
VStack {
loanViewModel.loan.map({ loan in
NavigationLink(destination: LoanDetailView(loanViewModel: loanViewModel)) {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -53,7 +53,7 @@ struct LoanRow : View {
#if DEBUG
struct LoanRow_Previews : PreviewProvider {
static var previews: some View {
return Group {
Group {
LoanRow(loanViewModel: loanViewModels[0])
.environment(\.colorScheme, .dark)
.previewLayout(.fixed(width: 300, height: 100))
Expand Down
2 changes: 1 addition & 1 deletion Books/Books/SignedInContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SignedInContainerView : View {
authentication.loansViewModel.map({ LoansView(loansViewModel: $0) })
.navigationBarTitle(Text("BTLB"))
.navigationBarItems(trailing: Button(action: {
self.showingAccount.toggle()
showingAccount.toggle()
}) {
Image(systemName: "person.crop.circle").imageScale(Image.Scale.large)
.accessibility(identifier: "Account")
Expand Down
8 changes: 4 additions & 4 deletions Books/Books/View Models/AuthenticationViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AuthenticationViewModel: ObservableObject {
}
var accountViewModel: AccountViewModel

@Published var authenticated: AuthenticationState = .authenticating {
@Published var state: AuthenticationState = .authenticating {
didSet {
self.handleAuthenticationUpdate(account: self.accountViewModel.account)
}
Expand All @@ -39,11 +39,11 @@ class AuthenticationViewModel: ObservableObject {
.sink(receiveCompletion: { completion in
switch completion {
case .failure(let authenticationError):
self.authenticated = .authenticationError(authenticationError)
self.state = .authenticationError(authenticationError)
case .finished: ()
}
}) { authenticated in
self.authenticated = authenticated
self.state = authenticated
}
}

Expand Down Expand Up @@ -72,7 +72,7 @@ class AuthenticationViewModel: ObservableObject {
return
}

if case AuthenticationState.authenticationComplete(.authenticated) = self.authenticated {
if case AuthenticationState.authenticationComplete(.authenticated) = self.state {
self.loansViewModel = LoansViewModel(account: account, authenticationManager: authenticationManager)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Books/Books/View Models/LoanViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LibraryCore
public class LoanViewModel: ObservableObject, Hashable {

public static func == (lhs: LoanViewModel, rhs: LoanViewModel) -> Bool {
return lhs.loan?.signature == rhs.loan?.signature
lhs.loan?.signature == rhs.loan?.signature
}

public func hash(into hasher: inout Hasher) {
Expand Down
2 changes: 2 additions & 0 deletions Books/Books/Views/LoanDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ struct LoanDetailView_Previews: PreviewProvider {
loan.material = "Material"
loan.materialName = "Buch Erwachsene"
loan.isReserved = false

let viewModel = LoanViewModel(loan: loan)

return LoanDetailView(loanViewModel: viewModel)
.environment(\.colorScheme, .light)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension XCUIApplication {
///
/// ```
/// app = XCUIApplication()
/// app.launch(options: [.stub(.networkRequests, in: self), .clean])
/// app.launch(options: [.stub(.networkRequests, in: self), .cleanKeychain])
/// ```
///
/// - Parameter options: the options to apply.
Expand Down Expand Up @@ -54,6 +54,10 @@ enum StubbingSubject {
}

extension XCUIApplication {

/// Adds a launch option to the launch of the application under test.
///
/// - Parameter option: The option to add
func addOption(_ option: LaunchOption) {
let processInfo = ProcessInfo()

Expand All @@ -69,6 +73,9 @@ extension XCUIApplication {
}
}

/// Removes a launch option of the application under test.
///
/// - Parameter option: The option to remove
func removeOption(_ option: LaunchOption) {

switch option {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension XCUIApplication {
///
/// ```
/// app = XCUIApplication()
/// app.launch(options: [.stub(.networkRequests, in: self), .clean])
/// app.launch(options: [.stub(.networkRequests, in: self), .cleanKeychain])
/// ```
///
/// - Parameter options: the options to apply.
Expand Down Expand Up @@ -54,6 +54,10 @@ enum StubbingSubject {
}

extension XCUIApplication {

/// Adds a launch option to the launch of the application under test.
///
/// - Parameter option: The option to add
func addOption(_ option: LaunchOption) {
let processInfo = ProcessInfo()

Expand All @@ -69,6 +73,9 @@ extension XCUIApplication {
}
}

/// Removes a launch option of the application under test.
///
/// - Parameter option: The option to remove
func removeOption(_ option: LaunchOption) {

switch option {
Expand Down
18 changes: 9 additions & 9 deletions LibraryCore/Sources/LibraryCore/API/RequestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ final class RequestBuilder {

/// - returns: An optional `URLRequest` for the given body and SOAP action
private func request(with body: Data?, path: String, action: String) -> URLRequest? {
return URLRequest.request(method: "POST",
host: "zones.buecherhallen.de",
path: path,
body: body,
headers: ["Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://bibliomondo.com/websevices/\(action)",
"Accept": "*/*",
"Accept-Language": "en-us",
"Accept-Encoding": "br, gzip, deflate"])
URLRequest.request(method: "POST",
host: "zones.buecherhallen.de",
path: path,
body: body,
headers: ["Content-Type": "text/xml; charset=utf-8",
"SOAPAction": "http://bibliomondo.com/websevices/\(action)",
"Accept": "*/*",
"Accept-Language": "en-us",
"Accept-Encoding": "br, gzip, deflate"])
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import Foundation

/// An Authentication Manager stub
public class AuthenticationManagerStub: AuthenticationManager {
public var authenticated: AuthenticationState = .authenticating
public var state: AuthenticationState = .authenticating
public var error: NSError? = nil
public var stubbedSessionIdentifier: String? = nil

public override func authenticateAccount(username: String?, password: String?) {
authenticatedSubject.send(authenticated)
authenticatedSubject.send(state)
}

override func sessionIdentifier(for accountIdentifier: String) -> String? {
return stubbedSessionIdentifier
stubbedSessionIdentifier
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class FlamingoCharge: Equatable {
}

static func ==(lhs: FlamingoCharge, rhs: FlamingoCharge) -> Bool {
return lhs.reason == rhs.reason &&
lhs.date == rhs.date &&
lhs.debit == rhs.debit &&
lhs.credit == rhs.credit
lhs.reason == rhs.reason &&
lhs.date == rhs.date &&
lhs.debit == rhs.debit &&
lhs.credit == rhs.credit
}

var debugDescription: String {
Expand All @@ -45,8 +45,8 @@ class FlamingoAccount {

init?(identifier: String?, name: String?, email: String?, charges: [FlamingoCharge] = []) {
guard let identifier = identifier,
let name = name, let email = email else {
return nil
let name = name, let email = email else {
return nil
}

self.identifier = identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class FlamingoInfoPair: Equatable {
}

static func ==(lhs: FlamingoInfoPair, rhs: FlamingoInfoPair) -> Bool {
return lhs.title == rhs.title && lhs.content == rhs.content
lhs.title == rhs.title && lhs.content == rhs.content
}
}

extension FlamingoInfoPair: CustomDebugStringConvertible {

var debugDescription: String {
return "FlamingoInfoPair(title: \"\(title)\", content: \"\(content)\")"
"FlamingoInfoPair(title: \"\(title)\", content: \"\(content)\")"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import Foundation
public extension ProcessInfo {
/// Returns `true` if the `ProcessInfo` contains a `THE_STUBBORN_NETWORK_UI_TESTING` environment variable.
var isUITesting: Bool {
get {
return environment["THE_STUBBORN_NETWORK_UI_TESTING"] != nil
}
environment["THE_STUBBORN_NETWORK_UI_TESTING"] != nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NetworkClient {
}

func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask {
return session.dataTask(with: request, completionHandler: completionHandler)
session.dataTask(with: request, completionHandler: completionHandler)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct SensitiveDataProcessor: BodyDataProcessor {
}

func dataForDeliveringResponseBody(data: Data?, of request: URLRequest) -> Data? {
return data
data
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class KeychainMock: TestableKeychainProvider {
}

func password(for account: String) -> String? {
return addedKeychainItems[account]
addedKeychainItems[account]
}

func deletePassword(of account: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PublicLibraryScraperTests: XCTestCase {
let loanDetailRequestB = try XCTUnwrap(RequestBuilder.default.itemDetailsRequest(itemIdentifier: "T01684642X"))
stubbornNetwork.stub(request: loanDetailRequestB, data: publicLoanDetailResponseBody)
scraper.loans(account, authenticationManager: AuthenticationManager.stubbed({ (manager) in
manager.authenticated = .authenticationComplete(.authenticated)
manager.state = .authenticationComplete(.authenticated)
manager.stubbedSessionIdentifier = "abc"
})) { (error, loans) -> (Void) in
XCTAssertEqual(loans.count, 2)
Expand Down
4 changes: 2 additions & 2 deletions LibraryCore/Tests/LibraryCoreTests/TestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ final class TestHelper {
}

static var keychainMock: TestableKeychainProvider {
return KeychainMock()
KeychainMock()
}

static func accountStub() -> AccountModel {
return AccountModel()
AccountModel()
}
}
2 changes: 1 addition & 1 deletion LibraryCore/Tests/LibraryCoreTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
[
testCase(LibraryCoreTests.allTests),
]
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
For the Xcode UITests it comes handy to prepare the keyboard in advance so that the monkey can type properly:

`defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false`

[![Build Status](https://travis-ci.com/q231950/Books.svg?branch=master)](https://travis-ci.com/q231950/Books)