-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mederic
committed
Aug 22, 2018
1 parent
381a5ae
commit 1321611
Showing
8 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// SignupParams.swift | ||
// OmiseGO | ||
// | ||
// Created by Mederic Petit on 22/8/18. | ||
// Copyright © 2017-2018 Omise Go Pte. Ltd. All rights reserved. | ||
// | ||
|
||
/// Represents a structure used to signup a new user | ||
public struct SignupParams { | ||
/// The email to use for signup | ||
public let email: String | ||
/// The password to use for signup | ||
public let password: String | ||
/// The password confirmation that should match the password | ||
public let passwordConfirmation: String | ||
/// An optional redirect URL if you want to use an other page from the default one | ||
public let redirectURL: String? | ||
/// An optional success URL to redirect the user to upon successful verification | ||
public let successURL: String? | ||
|
||
/// Initialize the params used to signup a user | ||
/// | ||
/// - Parameters: | ||
/// - email: The email of the user | ||
/// - password: The password of the user | ||
/// - passwordConfirmation: The password confirmation that should match the password | ||
/// - redirectURL: An optional redirect URL if you want to use an other page from the default one | ||
/// - successURL: An optional success URL to redirect the user to upon successful verification | ||
public init(email: String, | ||
password: String, | ||
passwordConfirmation: String, | ||
redirectURL: String? = nil, | ||
successURL: String? = nil) { | ||
self.email = email | ||
self.password = password | ||
self.passwordConfirmation = passwordConfirmation | ||
self.redirectURL = redirectURL | ||
self.successURL = successURL | ||
} | ||
} | ||
|
||
extension SignupParams: APIParameters { | ||
private enum CodingKeys: String, CodingKey { | ||
case email | ||
case password | ||
case passwordConfirmation = "password_confirmation" | ||
case redirectURL = "redirect_url" | ||
case successURL = "success_url" | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(email, forKey: .email) | ||
try container.encode(password, forKey: .password) | ||
try container.encode(passwordConfirmation, forKey: .passwordConfirmation) | ||
try container.encodeIfPresent(redirectURL, forKey: .redirectURL) | ||
try container.encodeIfPresent(successURL, forKey: .successURL) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// SignupFixtureTests.swift | ||
// Tests | ||
// | ||
// Created by Mederic Petit on 22/8/18. | ||
// Copyright © 2017-2018 Omise Go Pte. Ltd. All rights reserved. | ||
// | ||
|
||
@testable import OmiseGO | ||
import XCTest | ||
|
||
class SignupFixtureTests: XCTestCase { | ||
var testClient: FixtureClientAPI { | ||
let bundle = Bundle(for: FixtureClientTestCase.self) | ||
let url = bundle.url(forResource: "client_fixtures", withExtension: nil)! | ||
let credentials = ClientCredential(apiKey: "some_api_key") | ||
let config = ClientConfiguration(baseURL: "http://localhst:4000", credentials: credentials) | ||
return FixtureClientAPI(fixturesDirectoryURL: url, config: config) | ||
} | ||
|
||
func testSignupSuccessfully() { | ||
let expectation = self.expectation(description: "Signup a user successfully") | ||
XCTAssertNil(try! self.testClient.config.credentials.authentication()) | ||
let client = self.testClient | ||
let params = SignupParams(email: "email@example.com", | ||
password: "password", | ||
passwordConfirmation: "password") | ||
let request = client.signup(withParams: params) { result in | ||
defer { expectation.fulfill() } | ||
switch result { | ||
case let .fail(error: error): | ||
XCTFail(error.message) | ||
case .success(data: _): break | ||
} | ||
} | ||
XCTAssertNotNil(request) | ||
waitForExpectations(timeout: 15.0, handler: nil) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Tests/Client/FixtureTests/client_fixtures/api/user.signup.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "1", | ||
"success": true, | ||
"data": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters