This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
aab3275
commit 7524d82
Showing
11 changed files
with
162 additions
and
197 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,98 @@ | ||
using Get = Account.Get; | ||
using Login = Account.Login; | ||
using Save = Account.Save; | ||
using Verify = Account.Verify; | ||
|
||
namespace Tests.Account; | ||
|
||
public class AccountTests : TestClass<Fixture> | ||
{ | ||
public AccountTests(Fixture f, ITestOutputHelper o) : base(f, o) { } | ||
|
||
[Fact, Priority(1)] | ||
public async Task Account_Creation() | ||
{ | ||
var req = Fixture.SaveRequest; | ||
|
||
var (rsp, res) = await Fixture.Client.POSTAsync<Save.Endpoint, Save.Request, Save.Response>(req); | ||
|
||
rsp!.IsSuccessStatusCode.Should().BeTrue(); | ||
res!.EmailSent.Should().BeTrue(); | ||
res.ID.Should().NotBeNullOrEmpty(); | ||
|
||
Fixture.AccountID = res.ID; | ||
|
||
var acc = await DB.Find<Dom.Account>().OneAsync(res.ID); | ||
|
||
acc!.Email.Should().Be(req.EmailAddress.ToLower()); | ||
acc.IsEmailVerified.Should().BeFalse(); | ||
} | ||
|
||
[Fact, Priority(2)] | ||
public async Task Account_Verification() | ||
{ | ||
var accountID = Fixture.AccountID; | ||
|
||
var code = (await DB | ||
.Find<Dom.Account>() | ||
.OneAsync(accountID))! | ||
.EmailVerificationCode; | ||
|
||
await Fixture.Client.POSTAsync<Verify.Endpoint, Verify.Request>(new() | ||
{ | ||
ID = accountID!, | ||
Code = code | ||
}); | ||
|
||
var verified = await DB | ||
.Find<Dom.Account, bool>() | ||
.Match(a => a.ID == accountID) | ||
.Project(a => a.IsEmailVerified) | ||
.ExecuteSingleAsync(); | ||
|
||
verified.Should().BeTrue(); | ||
} | ||
|
||
[Fact, Priority(3)] | ||
public async Task Account_Login() | ||
{ | ||
var (rsp, res) = await Fixture.Client.POSTAsync<Login.Endpoint, Login.Request, Login.Response>(new() | ||
{ | ||
UserName = Fixture.SaveRequest.EmailAddress, | ||
Password = Fixture.SaveRequest.Password | ||
}); | ||
|
||
var acc = await DB.Find<Dom.Account>().OneAsync(Fixture.AccountID); | ||
|
||
rsp!.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); | ||
res!.FullName.Should().Be($"{acc!.Title} {acc.FirstName} {acc.LastName}"); | ||
res.PermissionSet.Should().HaveCount(7); | ||
res.Token.Value.Should().NotBeNull(); | ||
|
||
Fixture.JwtToken = res.Token.Value; | ||
} | ||
|
||
[Fact, Priority(4)] | ||
public async Task Account_Retrieve() | ||
{ | ||
Fixture.Client.DefaultRequestHeaders.Authorization = new("Bearer", Fixture.JwtToken); | ||
|
||
var (_, res) = await Fixture.Client.GETAsync<Get.Endpoint, Get.Response>(); | ||
|
||
var acc = await DB.Find<Dom.Account>().OneAsync(res!.AccountID); | ||
|
||
var match = | ||
acc!.Email == res.EmailAddress && | ||
acc.Title == res.Title && | ||
acc.FirstName == res.FirstName && | ||
acc.LastName == res.LastName && | ||
acc.Address.Street == res.Street && | ||
acc.Address.City == res.City && | ||
acc.Address.State == res.State && | ||
acc.Address.ZipCode == res.ZipCode && | ||
acc.Address.CountryCode == res.CountryCode && | ||
acc.Mobile == res.Mobile; | ||
|
||
match.Should().BeTrue(); | ||
} | ||
} |
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,22 @@ | ||
using Bogus; | ||
using Save = Account.Save; | ||
|
||
namespace Tests.Account; | ||
|
||
static class Fakes | ||
{ | ||
public static Save.Request SaveRequest(this Faker f) => new() | ||
{ | ||
City = f.Address.City(), | ||
CountryCode = f.Address.County(), | ||
EmailAddress = f.Internet.Email(), | ||
FirstName = f.Name.FirstName(), | ||
LastName = f.Name.LastName(), | ||
Mobile = f.Phone.PhoneNumber("##########"), | ||
Password = f.Internet.Password(10), | ||
State = f.Address.State(), | ||
Street = f.Address.StreetName(), | ||
Title = f.Name.Prefix(), | ||
ZipCode = f.Address.ZipCode(), | ||
}; | ||
} |
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,21 @@ | ||
using Save = Account.Save; | ||
|
||
namespace Tests.Account; | ||
|
||
public class Fixture : TestFixture<Program> | ||
{ | ||
public Fixture(IMessageSink s) : base(s) { } | ||
|
||
internal Save.Request SaveRequest { get; private set; } = default!; | ||
public string AccountID { get; set; } = ""; | ||
public string JwtToken { get; set; } = ""; | ||
|
||
protected override Task SetupAsync() | ||
{ | ||
SaveRequest = Fake.SaveRequest(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
protected override Task TearDownAsync() | ||
=> DB.DeleteAsync<Dom.Account>(a => a.ID == AccountID); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.