-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permissions tests for API Key list and create actions #5153
Conversation
|
||
var model = GetModelForApiKeys(currentUser); | ||
|
||
Assert.True(model.PackageOwners.Any(o => o.Owner == currentUser.Username && o.CanPushNew)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this test that PackageOwners contains a single entry for the current user? Maybe test name could be something like PackageOwners_ContainsSingleCurrentUserEntryWithPushNew
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll combine with the others
|
||
var model = GetModelForApiKeys(currentUser); | ||
|
||
Assert.True(model.PackageOwners.All(o => o.Owner == currentUser.Username && o.CanPushNew)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this testing same as previous, but for site admin? Is All used instead of Any only because the FakeAdminUser isn't in an organization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and yes
var model = GetModelForApiKeys(currentUser); | ||
|
||
Assert.True(model.PackageOwners.Any(o => o.Owner == currentUser.Username && o.CanPushNew)); | ||
Assert.True(model.PackageOwners.Any(o => o.Owner == organization.Username && o.CanPushNew == isAdmin)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first assert is the same as the first test... current user should be the first entry. I could combine w/ that.
For the second assert, I would change it to test that PackageOwners contains a single entry for the Org account at index 2. Makes it a stronger test, and we'll catch if we have a bug with duplicate entries or not listing the current user first.
var user = fakes.Admin; | ||
var otherUser = fakes.User; | ||
|
||
return WhenScopeOwnerDoesNotMatch_ReturnsBadRequest(user, otherUser); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fakes.Admin
is site admin?
Can this be combined w/ previous test, and just take 2 Users as Theory args?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and yes
@chenriksson Fixed the tests as requested. |
|
||
Assert.Equal(1, model.PackageOwners.Count(o => o.Owner == organization.Username && o.CanPushNew == isAdmin)); | ||
} | ||
public static IEnumerable<object[]> OrganizationIsNotInPackageOwnersIfNotMember_Data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space between
{ | ||
get | ||
{ | ||
foreach (var currentUser in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be:
yield return new object[] { TestUtility.FakeUser };
yield return new object[] { TestUtility.FakeAdminUser };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have a lot of test code converting entities to object arrays, could consider a MemberDataHelper class:
public static class MemberDataHelper {
object[] AsMemberData(this User user) { return new object[] { user }; }
}
public class TestClass {
public static IEnumerable<object[]> TestData {
get {
yield return TestUtility.FakeUser.AsMemberData();
yield return TestUtility.FakeAdminUser.AsMemberData();
}
}
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(User user) { ... }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
public static class MemberDataHelper {
public static object[] AsData(params object[] objects)
{
return objects;
}
}
public class TestClass {
public static IEnumerable<object[]> TestData {
get {
yield return MemberDataHelper.AsData(TestUtility.FakeUser);
yield return MemberDataHelper.AsData(TestUtility.FakeAdminUser);
}
}
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(User user) { ... }
}
|
||
var model = GetModelForApiKeys(currentUser); | ||
|
||
Assert.True(!model.PackageOwners.Any(o => o.Owner == organization.Username)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting count instead of Any
would provide a better message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address/ignore comment then .
No description provided.