Added tests for calendarwebapp.authenticator.AuthInfo

This commit is contained in:
Johannes Loher 2017-10-26 20:23:02 +02:00
parent 4959c67e89
commit 464c224d72
2 changed files with 35 additions and 3 deletions

View file

@ -54,12 +54,12 @@ struct AuthInfo
string passwordHash;
Role role;
bool isUser()
bool isUser() const pure @safe nothrow
{
return role == Role.User;
}
bool isAdmin()
bool isAdmin() const pure @safe nothrow
{
return role == Role.Admin;
}

View file

@ -31,7 +31,7 @@ public:
}
}
@("Test MongoDBAuthenticator")
@("MongoDBAuthenticator.checkUser")
@system unittest
{
auto collection = mock!Collection;
@ -52,3 +52,35 @@ public:
authenticator.checkUser("foo", "bar").isNull.shouldBeFalse;
authenticator.checkUser("foo", "baz").isNull.shouldBeTrue;
}
@("AuthInfo.isUser success")
@safe unittest
{
AuthInfo auth;
auth.role = Role.User;
auth.isUser.shouldBeTrue;
}
@("AuthInfo.isUser failure")
@safe unittest
{
AuthInfo auth;
auth.role = Role.Admin;
auth.isUser.shouldBeFalse;
}
@("AuthInfo.isAdmin success")
@safe unittest
{
AuthInfo auth;
auth.role = Role.Admin;
auth.isAdmin.shouldBeTrue;
}
@("AuthInfo.isAdmin failure")
@safe unittest
{
AuthInfo auth;
auth.role = Role.User;
auth.isAdmin.shouldBeFalse;
}