Created
May 1, 2022 09:51
-
-
Save mrpmorris/c5debcea41ff31e47a4b9bbb582c9ce8 to your computer and use it in GitHub Desktop.
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
using Gambit.GameServer.Contracts; | |
using Gambit.GameServerIntegrationTests.Drivers; | |
namespace Gambit.GameServerIntegrationTests.Features.Users; | |
[Binding] | |
public class SignInStepDefinitions | |
{ | |
private readonly UserDriver UserDriver; | |
public SignInStepDefinitions(UserDriver userDriver) | |
{ | |
UserDriver = userDriver; | |
} | |
[Given(@"A user has signed up")] | |
public Task GivenAUserHasSignedUp() | |
{ | |
string id = Guid.NewGuid().ToString().Replace("-", ""); | |
string emailAddress = $"{id}@{id}.com"; | |
return UserDriver.SignUpAsync( | |
userName: id, | |
emailAddress: emailAddress, | |
passPhrase: "Qwerty123!", | |
walletAddress: id); | |
} | |
[Given(@"Has confirmed their identity")] | |
public Task GivenHasConfirmedTheirIdentity() | |
{ | |
return UserDriver.ConfirmIdentityAsync( | |
emailAddress: UserDriver.EmailAddress, | |
confirmationCode: UserDriver.IdentityConfirmationCode); | |
} | |
[When(@"The user requests a sign-in code")] | |
[Given(@"Has requested a sign-in code")] | |
public Task WhenTheUserRequestsASignInCode() | |
{ | |
return UserDriver.RequestSignInCodeAsync( | |
emailAddress: UserDriver.EmailAddress, | |
userName: UserDriver.UserName); | |
} | |
[Then(@"They should receive a sign-in code")] | |
public void ThenTheyShouldReceiveASign_InCode() | |
{ | |
Assert.Equal(ResponseStatus.Success, UserDriver.RequestSignInCodeResponse?.Status); | |
} | |
[Given(@"Has not confirmed their identity")] | |
public void GivenHasNotConfirmedTheirIdentity() | |
{ | |
// This is a no-operation | |
} | |
[When(@"The user signs in with the wrong sign-in code")] | |
public Task WhenTheUserSignsInWithTheWrongSign_InCode() | |
{ | |
return UserDriver.SignInAsync( | |
emailAddress: UserDriver.EmailAddress, | |
userName: UserDriver.UserName, | |
passPhrase: "Qwerty123!", | |
signInOneTimeCode: "ABCDEF"); | |
} | |
[When(@"The user signs in with the correct sign-in code")] | |
public Task WhenTheUserSignsInWithTheCorrectSign_InCode() | |
{ | |
return UserDriver.SignInAsync( | |
emailAddress: UserDriver.EmailAddress, | |
userName: UserDriver.UserName, | |
passPhrase: "Qwerty123!", | |
signInOneTimeCode: UserDriver.SignInOneTimeCode); | |
} | |
[Then(@"They should receive a respond with the error ""([^""]*)""")] | |
public void ThenTheyShouldReceiveARespondWithTheError(string errorMessage) | |
{ | |
Assert.Equal(ResponseStatus.BadRequest, UserDriver.LastResponse?.Status); | |
Assert.Equal(errorMessage, UserDriver.LastResponse?.ErrorMessage); | |
} | |
[Then(@"They should receive a session token")] | |
public void ThenTheyShouldReceiveASessionToken() | |
{ | |
Assert.Equal(ResponseStatus.Success, UserDriver.SignInResponse?.Status); | |
Assert.NotNull(UserDriver.SignInResponse?.SessionToken); | |
} | |
} |
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
using Gambit.GameServer.Contracts; | |
using Gambit.GameServer.Contracts.UserUseCases; | |
namespace Gambit.GameServerIntegrationTests.Drivers; | |
public class UserDriver | |
{ | |
public string? UserName { get; private set; } | |
public string? EmailAddress { get; private set; } | |
public string? IdentityConfirmationCode { get; private set; } | |
public string? SignInOneTimeCode { get; private set; } | |
public string? SessionToken { get; private set; } | |
public string? ConnectToServerOneTimeCode { get; private set; } | |
public Response? LastResponse { get; private set; } | |
public SignUpResponse? SignUpResponse { get; private set; } | |
public ConfirmIdentityResponse? ConfirmIdentityResponse { get; private set; } | |
public RequestSignInCodeResponse? RequestSignInCodeResponse { get; private set; } | |
public SignInResponse? SignInResponse { get; private set; } | |
public async Task SignUpAsync( | |
string? userName, | |
string? emailAddress, | |
string? passPhrase, | |
string? walletAddress) | |
{ | |
ArgumentNullException.ThrowIfNull(userName); | |
ArgumentNullException.ThrowIfNull(passPhrase); | |
ArgumentNullException.ThrowIfNull(emailAddress); | |
ArgumentNullException.ThrowIfNull(walletAddress); | |
UserName = userName; | |
EmailAddress = emailAddress; | |
var command = new SignUpCommand( | |
UserName: userName, | |
EmailAddress: emailAddress, | |
MobileNumber: null, | |
WalletAddress: walletAddress, | |
Passphrase: passPhrase); | |
SignUpResponse = await Client.PostAsync("/api/v1/users/sign-up", command); | |
LastResponse = SignUpResponse; | |
IdentityConfirmationCode = Client.IdentityConfirmationCode; | |
} | |
public async Task ConfirmIdentityAsync( | |
string? emailAddress, | |
string? confirmationCode) | |
{ | |
ArgumentNullException.ThrowIfNull(emailAddress); | |
ArgumentNullException.ThrowIfNull(confirmationCode); | |
EmailAddress = emailAddress; | |
var command = new ConfirmIdentityCommand( | |
EmailAddress: emailAddress, | |
ConfirmationCode: confirmationCode); | |
ConfirmIdentityResponse = await Client.PostAsync("/api/v1/users/confirm-identity", command); | |
LastResponse = ConfirmIdentityResponse; | |
} | |
public async Task RequestSignInCodeAsync( | |
string? emailAddress, | |
string? userName) | |
{ | |
ArgumentNullException.ThrowIfNull(emailAddress); | |
ArgumentNullException.ThrowIfNull(userName); | |
EmailAddress = emailAddress; | |
UserName = userName; | |
var command = new RequestSignInCodeCommand( | |
EmailAddress: emailAddress, | |
UserName: userName); | |
RequestSignInCodeResponse = await Client.PostAsync("/api/v1/users/request-sign-in-code", command); | |
LastResponse = RequestSignInCodeResponse; | |
SignInOneTimeCode = Client.SignInOneTimeCode; | |
} | |
public async Task SignInAsync( | |
string? emailAddress, | |
string? userName, | |
string? passPhrase, | |
string? signInOneTimeCode) | |
{ | |
ArgumentNullException.ThrowIfNull(emailAddress); | |
ArgumentNullException.ThrowIfNull(userName); | |
ArgumentNullException.ThrowIfNull(passPhrase); | |
ArgumentNullException.ThrowIfNull(signInOneTimeCode); | |
EmailAddress = emailAddress; | |
UserName = userName; | |
var command = new SignInCommand( | |
EmailAddress: emailAddress, | |
UserName: userName, | |
Passphrase: passPhrase, | |
OneTimeCode: signInOneTimeCode); | |
SignInResponse = await Client.PostAsync("/api/v1/users/sign-in", command); | |
LastResponse = SignInResponse; | |
SignInOneTimeCode = Client.SignInOneTimeCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment