Skip to content

Commit

Permalink
Submit login arguments when performing login
Browse files Browse the repository at this point in the history
  • Loading branch information
ShezHsky committed Jul 18, 2017
1 parent 63a0708 commit 76f7606
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
12 changes: 10 additions & 2 deletions Eurofurence/Application/EurofurenceApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ class EurofurenceApplication: LoginStateObserver {
}
}

func login() {
jsonPoster.post("https://app.eurofurence.org/api/v2/Tokens/RegSys", body: Data())
func login(registrationNumber: Int, username: String, password: String) {
do {
let postArguments: [String : Any] = ["RegNo": registrationNumber,
"Username": username,
"Password": password]
let jsonData = try JSONSerialization.data(withJSONObject: postArguments, options: [])
jsonPoster.post("https://app.eurofurence.org/api/v2/Tokens/RegSys", body: jsonData)
} catch {
print("Unable to perform login due to error: \(error)")
}
}

func registerRemoteNotifications(deviceToken: Data) {
Expand Down
26 changes: 25 additions & 1 deletion EurofurenceTests/Application Tests/WhenLoggingIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WhenLoggingIn: XCTestCase {

func testTheLoginEndpointShouldReceievePOSTRequest() {
let context = ApplicationTestBuilder().build()
context.application.login()
context.application.login(registrationNumber: 0, username: "", password: "")

XCTAssertEqual("https://app.eurofurence.org/api/v2/Tokens/RegSys", context.jsonPoster.postedURL)
}
Expand All @@ -23,4 +23,28 @@ class WhenLoggingIn: XCTestCase {
XCTAssertNil(context.jsonPoster.postedURL)
}

func testTheLoginRequestShouldReceieveJSONPayloadWithRegNo() {
let context = ApplicationTestBuilder().build()
let registrationNumber = 42
context.application.login(registrationNumber: registrationNumber, username: "", password: "")

XCTAssertEqual(registrationNumber, context.jsonPoster.postedJSONValue(forKey: "RegNo"))
}

func testTheLoginRequestShouldReceieveJSONPayloadWithUsername() {
let context = ApplicationTestBuilder().build()
let username = "Some awesome guy"
context.application.login(registrationNumber: 0, username: username, password: "")

XCTAssertEqual(username, context.jsonPoster.postedJSONValue(forKey: "Username"))
}

func testTheLoginRequestShouldReceieveJSONPayloadWithPassword() {
let context = ApplicationTestBuilder().build()
let password = "It's a secrent"
context.application.login(registrationNumber: 0, username: "", password: password)

XCTAssertEqual(password, context.jsonPoster.postedJSONValue(forKey: "Password"))
}

}

0 comments on commit 76f7606

Please sign in to comment.