Skip to content

Commit

Permalink
Added and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MercurialPony committed Dec 3, 2023
1 parent a110a06 commit a81089a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion Izzy-MoonbotTests/Tests/ConfigCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,40 @@ public async Task ConfigCommand_EditEveryItemAsync()
Assert.AreEqual(cfg.WittyCooldown, 50);
Assert.AreEqual("I've set `WittyCooldown` to the following content: 50", generalChannel.Messages.Last().Content);

// post .config MonitoringEnabled false
Assert.AreEqual(cfg.MonitoringEnabled, true);
context = await client.AddMessageAsync(guild.Id, generalChannel.Id, sunny.Id, "post .config MonitoringEnabled false");
await ConfigCommand.TestableConfigCommandAsync(context, cfg, cd, "MonitoringEnabled", "false");
Assert.AreEqual(cfg.MonitoringEnabled, false);
Assert.AreEqual("I've set `MonitoringEnabled` to the following content: false", generalChannel.Messages.Last().Content);

// post .config MonitoringChannel <#2>
Assert.AreEqual(cfg.MonitoringChannel, 0ul);
context = await client.AddMessageAsync(guild.Id, generalChannel.Id, sunny.Id, ".config MonitoringChannel <#2>");
await ConfigCommand.TestableConfigCommandAsync(context, cfg, cd, "MonitoringChannel", "<#2>");
Assert.AreEqual(cfg.MonitoringChannel, 2ul);
Assert.AreEqual("I've set `MonitoringChannel` to the following content: <#2>", generalChannel.Messages.Last().Content);

// post .config MonitoringMessageInterval 60
Assert.AreEqual(cfg.MonitoringMessageInterval, 604800ul);
context = await client.AddMessageAsync(guild.Id, generalChannel.Id, sunny.Id, "post .config MonitoringMessageInterval 60");
await ConfigCommand.TestableConfigCommandAsync(context, cfg, cd, "MonitoringMessageInterval", "60");
Assert.AreEqual(cfg.MonitoringMessageInterval, 60ul);
Assert.AreEqual("I've set `MonitoringMessageInterval` to the following content: 60", generalChannel.Messages.Last().Content);

// post .config MonitoringBypassRoles add <@&1>
TestUtils.AssertSetsAreEqual(new HashSet<ulong>(), cfg.MonitoringBypassRoles);
context = await client.AddMessageAsync(guild.Id, generalChannel.Id, sunny.Id, ".config MonitoringBypassRoles add <@&1>");
await ConfigCommand.TestableConfigCommandAsync(context, cfg, cd, "MonitoringBypassRoles", "add <@&1>");
TestUtils.AssertSetsAreEqual(new HashSet<ulong> { 1ul }, cfg.MonitoringBypassRoles);
Assert.AreEqual($"I added the following content to the `MonitoringBypassRoles` role list:\n" +
$"Alicorn",
generalChannel.Messages.Last().Content);

// Ensure we can't forget to keep this test up to date
var configPropsCount = typeof(Config).GetProperties().Length;

Assert.AreEqual(55, configPropsCount,
Assert.AreEqual(59, configPropsCount,
$"\nIf you just added or removed a config item, then this test is probably out of date");

Assert.AreEqual(configPropsCount * 2, generalChannel.Messages.Count(),
Expand Down
4 changes: 2 additions & 2 deletions Izzy-MoonbotTests/Tests/FileHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public void ConfigRoundTrip()
"MonitoringEnabled": true,
"MonitoringChannel": 0,
"MonitoringMessageInterval": 604800,
"MonitoringBypassRoles": [],
}
"MonitoringBypassRoles": []
}
""", serialized);
}

Expand Down

0 comments on commit a81089a

Please sign in to comment.