diff --git a/Eurofurence.xcodeproj/project.pbxproj b/Eurofurence.xcodeproj/project.pbxproj index c79077a17..9fadc0614 100644 --- a/Eurofurence.xcodeproj/project.pbxproj +++ b/Eurofurence.xcodeproj/project.pbxproj @@ -182,6 +182,7 @@ A034379A14212C5E996E6321 /* Pods_Eurofurence.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A81694C40AA0176899E15028 /* Pods_Eurofurence.framework */; }; CA2B4FA41F1E9FA600F007E1 /* WhenLoggingIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2B4FA31F1E9FA600F007E1 /* WhenLoggingIn.swift */; }; CA2B4FA61F1EA1B300F007E1 /* ApplicationTestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2B4FA51F1EA1B300F007E1 /* ApplicationTestBuilder.swift */; }; + CA2B4FA81F1EA72A00F007E1 /* LoginArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA2B4FA71F1EA72A00F007E1 /* LoginArguments.swift */; }; CAD780371F1D415A002A8333 /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD780361F1D415A002A8333 /* MessagesViewController.swift */; }; CAD780391F1D41C4002A8333 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD780381F1D41C4002A8333 /* LoginViewController.swift */; }; CAD780401F1D4C2A002A8333 /* WhenLoginStateChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD7803F1F1D4C2A002A8333 /* WhenLoginStateChanges.swift */; }; @@ -430,6 +431,7 @@ B4939A463603D9F022E19825 /* Pods-EurofurenceTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EurofurenceTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-EurofurenceTests/Pods-EurofurenceTests.debug.xcconfig"; sourceTree = ""; }; CA2B4FA31F1E9FA600F007E1 /* WhenLoggingIn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WhenLoggingIn.swift; path = "Application Tests/WhenLoggingIn.swift"; sourceTree = ""; }; CA2B4FA51F1EA1B300F007E1 /* ApplicationTestBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ApplicationTestBuilder.swift; path = "Application Tests/ApplicationTestBuilder.swift"; sourceTree = ""; }; + CA2B4FA71F1EA72A00F007E1 /* LoginArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoginArguments.swift; path = Login/LoginArguments.swift; sourceTree = ""; }; CAD780361F1D415A002A8333 /* MessagesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = ""; }; CAD780381F1D41C4002A8333 /* LoginViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = ""; }; CAD7803F1F1D4C2A002A8333 /* WhenLoginStateChanges.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WhenLoginStateChanges.swift; path = "Application Tests/WhenLoginStateChanges.swift"; sourceTree = ""; }; @@ -1126,6 +1128,7 @@ CAD780421F1D4CA3002A8333 /* LoginController.swift */, CAD7804F1F1E2D13002A8333 /* LoginCredentialStore.swift */, CAD780591F1E8E7D002A8333 /* KeychainLoginCredentialStore.swift */, + CA2B4FA71F1EA72A00F007E1 /* LoginArguments.swift */, ); name = Login; sourceTree = ""; @@ -1680,6 +1683,7 @@ D6F3D275FF81A313B9213277 /* AnnouncementCell.swift in Sources */, D6F3DAD590C051C8D0060172 /* EventViewController.swift in Sources */, D6F3D62A784F07D9C7A84DC8 /* KnowledgeEntryViewController.swift in Sources */, + CA2B4FA81F1EA72A00F007E1 /* LoginArguments.swift in Sources */, 78F555991F10D5A800BDA7D4 /* ReplaceViewControllersSegue.swift in Sources */, 9A0F87E51F1BAD2C00FF294B /* LocalNotificationStore.swift in Sources */, D6F3D2440B74E17B9A008DE0 /* NewsViewController.swift in Sources */, diff --git a/Eurofurence/Application/EurofurenceApplication.swift b/Eurofurence/Application/EurofurenceApplication.swift index 5ba4789b7..4e6f25da5 100644 --- a/Eurofurence/Application/EurofurenceApplication.swift +++ b/Eurofurence/Application/EurofurenceApplication.swift @@ -35,11 +35,11 @@ class EurofurenceApplication: LoginStateObserver { } } - func login(registrationNumber: Int, username: String, password: String) { + func login(_ arguments: LoginArguments) { do { - let postArguments: [String : Any] = ["RegNo": registrationNumber, - "Username": username, - "Password": password] + let postArguments: [String : Any] = ["RegNo": arguments.registrationNumber, + "Username": arguments.username, + "Password": arguments.password] let jsonData = try JSONSerialization.data(withJSONObject: postArguments, options: []) jsonPoster.post("https://app.eurofurence.org/api/v2/Tokens/RegSys", body: jsonData) } catch { diff --git a/Eurofurence/Services/Login/LoginArguments.swift b/Eurofurence/Services/Login/LoginArguments.swift new file mode 100644 index 000000000..33a524755 --- /dev/null +++ b/Eurofurence/Services/Login/LoginArguments.swift @@ -0,0 +1,17 @@ +// +// LoginArguments.swift +// Eurofurence +// +// Created by Thomas Sherwood on 18/07/2017. +// Copyright © 2017 Eurofurence. All rights reserved. +// + +import Foundation + +struct LoginArguments { + + var registrationNumber: Int + var username: String + var password: String + +} diff --git a/EurofurenceTests/Application Tests/ApplicationTestBuilder.swift b/EurofurenceTests/Application Tests/ApplicationTestBuilder.swift index 0e9b2c9ae..d67184ea0 100644 --- a/EurofurenceTests/Application Tests/ApplicationTestBuilder.swift +++ b/EurofurenceTests/Application Tests/ApplicationTestBuilder.swift @@ -23,6 +23,11 @@ class ApplicationTestBuilder { application.registerRemoteNotifications(deviceToken: deviceToken) } + func login(registrationNumber: Int = 0, username: String = "", password: String = "") { + let arguments = LoginArguments(registrationNumber: registrationNumber, username: username, password: password) + application.login(arguments) + } + func notifyUserLoggedIn(_ token: String = "", expires: Date = .distantFuture) { capturingLoginController.notifyUserLoggedIn(token, expires: expires) } diff --git a/EurofurenceTests/Application Tests/WhenLoggingIn.swift b/EurofurenceTests/Application Tests/WhenLoggingIn.swift index 8fd6526d3..6bfcfcecb 100644 --- a/EurofurenceTests/Application Tests/WhenLoggingIn.swift +++ b/EurofurenceTests/Application Tests/WhenLoggingIn.swift @@ -13,7 +13,7 @@ class WhenLoggingIn: XCTestCase { func testTheLoginEndpointShouldReceievePOSTRequest() { let context = ApplicationTestBuilder().build() - context.application.login(registrationNumber: 0, username: "", password: "") + context.login() XCTAssertEqual("https://app.eurofurence.org/api/v2/Tokens/RegSys", context.jsonPoster.postedURL) } @@ -26,7 +26,7 @@ class WhenLoggingIn: XCTestCase { func testTheLoginRequestShouldReceieveJSONPayloadWithRegNo() { let context = ApplicationTestBuilder().build() let registrationNumber = 42 - context.application.login(registrationNumber: registrationNumber, username: "", password: "") + context.login(registrationNumber: registrationNumber) XCTAssertEqual(registrationNumber, context.jsonPoster.postedJSONValue(forKey: "RegNo")) } @@ -34,7 +34,7 @@ class WhenLoggingIn: XCTestCase { func testTheLoginRequestShouldReceieveJSONPayloadWithUsername() { let context = ApplicationTestBuilder().build() let username = "Some awesome guy" - context.application.login(registrationNumber: 0, username: username, password: "") + context.login(username: username) XCTAssertEqual(username, context.jsonPoster.postedJSONValue(forKey: "Username")) } @@ -42,7 +42,7 @@ class WhenLoggingIn: XCTestCase { func testTheLoginRequestShouldReceieveJSONPayloadWithPassword() { let context = ApplicationTestBuilder().build() let password = "It's a secrent" - context.application.login(registrationNumber: 0, username: "", password: password) + context.login(password: password) XCTAssertEqual(password, context.jsonPoster.postedJSONValue(forKey: "Password")) }