Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GlobalX/PockyBot.NET into feature…
Browse files Browse the repository at this point in the history
…/31-results-trigger
  • Loading branch information
Evangelinexx committed Mar 31, 2020
2 parents 35e9c4c + 0f8dfac commit cc5a9a8
Show file tree
Hide file tree
Showing 38 changed files with 276 additions and 220 deletions.
34 changes: 17 additions & 17 deletions src/PockyBot.NET.Tests/Services/Triggers/HelpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class HelpTests

private const string BotName = "Pocky";
private const string SenderId = "testSender";
private readonly List<Role> noRoles = new List<Role>();
private readonly List<Role> adminRole = new List<Role>{new Role{UserRole = Roles.Admin}};
private readonly List<UserRole> noRoles = new List<UserRole>();
private readonly List<UserRole> adminRole = new List<UserRole>{new UserRole{Role = Role.Admin}};

private Message _message;
private Message _result;
Expand Down Expand Up @@ -126,22 +126,22 @@ public void ItShouldShowTheHelpMessageForNonAdminCommandsInADirectMessage(string
}

[Theory]
[InlineData(Commands.Finish, Roles.Finish)]
[InlineData(Commands.Finish, Roles.Admin)]
[InlineData(Commands.Reset, Roles.Reset)]
[InlineData(Commands.Reset, Roles.Admin)]
[InlineData(Commands.StringConfig, Roles.Admin)]
[InlineData(Commands.StringConfig, Roles.Config)]
[InlineData(Commands.RoleConfig, Roles.Admin)]
[InlineData(Commands.RoleConfig, Roles.Config)]
[InlineData(Commands.LocationWeight, Roles.Admin)]
[InlineData(Commands.LocationWeight, Roles.Config)]
[InlineData(Commands.RemoveUser, Roles.Admin)]
[InlineData(Commands.RemoveUser, Roles.RemoveUser)]
public void ItShouldShowTheHelpMessageForAdminCommandsToAdminUsers(string command, string userRole)
[InlineData(Commands.Finish, Role.Finish)]
[InlineData(Commands.Finish, Role.Admin)]
[InlineData(Commands.Reset, Role.Reset)]
[InlineData(Commands.Reset, Role.Admin)]
[InlineData(Commands.StringConfig, Role.Admin)]
[InlineData(Commands.StringConfig, Role.Config)]
[InlineData(Commands.RoleConfig, Role.Admin)]
[InlineData(Commands.RoleConfig, Role.Config)]
[InlineData(Commands.LocationWeight, Role.Admin)]
[InlineData(Commands.LocationWeight, Role.Config)]
[InlineData(Commands.RemoveUser, Role.Admin)]
[InlineData(Commands.RemoveUser, Role.RemoveUser)]
internal void ItShouldShowTheHelpMessageForAdminCommandsToAdminUsers(string command, Role userRole)
{
this.Given(x => GivenAHelpMessage(command))
.And(x => GivenTheUserHasRoles(new List<Role>{new Role{UserRole = userRole}}))
.And(x => GivenTheUserHasRoles(new List<UserRole>{new UserRole{Role = userRole}}))
.When(x => WhenRespondIsCalled())
.Then(x => ThenItShouldShowTheCommandHelpMessage(command))
.BDDfy();
Expand Down Expand Up @@ -207,7 +207,7 @@ private void GivenADirectMessageHelpMessage(string command)
};
}

private void GivenTheUserHasRoles(List<Role> roles)
private void GivenTheUserHasRoles(List<UserRole> roles)
{
_pockyUserRepository.GetUser(SenderId).Returns(new PockyUser
{
Expand Down
12 changes: 6 additions & 6 deletions src/PockyBot.NET.Tests/Services/Triggers/RoleConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal void TestUnsuccessfulDeleteRoleConfig(Message message, Person person, P
[Theory]
[MemberData(nameof(RoleConfigTestData.SuccessfulSetRoleConfigTestData), MemberType = typeof(RoleConfigTestData))]
internal void TestSuccessfulSetRoleConfig(Message message, Person person, PockyUser pockyUser,
Message response, string userId, string role)
Message response, string userId, Role role)
{
this.Given(x => GivenAMessage(message))
.And(x => GivenAPerson(person))
Expand All @@ -89,7 +89,7 @@ internal void TestSuccessfulSetRoleConfig(Message message, Person person, PockyU
[Theory]
[MemberData(nameof(RoleConfigTestData.SuccessfulDeleteRoleConfigTestData), MemberType = typeof(RoleConfigTestData))]
internal void TestSuccessfulDeleteRoleConfig(Message message, Person person, PockyUser pockyUser,
Message response, string userId, string role)
Message response, string userId, Role role)
{
this.Given(x => GivenAMessage(message))
.And(x => GivenAPerson(person))
Expand Down Expand Up @@ -143,20 +143,20 @@ private void ThenItShouldReturnAResponse(string[] responseLines)

private void ThenItShouldNotCallAddRole()
{
_pockyUserRepository.DidNotReceiveWithAnyArgs().AddRoleAsync(Arg.Any<string>(), Arg.Any<string>());
_pockyUserRepository.DidNotReceiveWithAnyArgs().AddRoleAsync(Arg.Any<string>(), Arg.Any<Role>());
}

private void ThenItShouldNotCallRemoveRole()
{
_pockyUserRepository.DidNotReceiveWithAnyArgs().RemoveRoleAsync(Arg.Any<string>(), Arg.Any<string>());
_pockyUserRepository.DidNotReceiveWithAnyArgs().RemoveRoleAsync(Arg.Any<string>(), Arg.Any<Role>());
}

private void ThenItShouldCallAddRole(string userId, string role)
private void ThenItShouldCallAddRole(string userId, Role role)
{
_pockyUserRepository.Received(1).AddRoleAsync(userId, role);
}

private void ThenItShouldCallRemoveRole(string userId, string role)
private void ThenItShouldCallRemoveRole(string userId, Role role)
{
_pockyUserRepository.Received(1).RemoveRoleAsync(userId, role);
}
Expand Down
14 changes: 7 additions & 7 deletions src/PockyBot.NET.Tests/Services/Triggers/UserLocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ private void GivenAMessage(Message message)

private void GivenUserHasPermission(bool hasPermission)
{
var roles = new List<UserRole>();
if (hasPermission)
{
roles.Add(new UserRole{Role = Role.Config});
}

_pockyUserRepository.GetUser(Arg.Any<string>())
.Returns(x => new PockyUser
{
Username = (string) x[0],
UserId = (string) x[0],
Roles = new List<Role>
{
new Role
{
UserRole = hasPermission ? "CONFIG" : "none"
}
}
Roles = roles
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IEnumerable<object[]> MapUsersToPegRecipientsTestData()
{
Username = "User 1",
UserId = "User1Id",
Roles = new List<Role>(),
Roles = new List<UserRole>(),
Location = new UserLocation{ Location = "Location1" },
PegsReceived = new List<Peg>
{
Expand Down Expand Up @@ -58,7 +58,7 @@ public static IEnumerable<object[]> MapUsersToPegRecipientsTestData()
{
Username = "User 2",
UserId = "User2Id",
Roles = new List<Role>(),
Roles = new List<UserRole>(),
Location = new UserLocation { Location = "Location1" },
PegsReceived = new List<Peg>(),
PegsGiven = new List<Peg>
Expand All @@ -78,7 +78,7 @@ public static IEnumerable<object[]> MapUsersToPegRecipientsTestData()
{
Username = "User 3",
UserId = "User3Id",
Roles = new List<Role>(),
Roles = new List<UserRole>(),
Location = new UserLocation { Location = "Location2" },
PegsReceived = new List<Peg>(),
PegsGiven = new List<Peg>
Expand Down
Loading

0 comments on commit cc5a9a8

Please sign in to comment.