Skip to content
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

Merged
merged 5 commits into from
Dec 12, 2017

Conversation

scottbommarito
Copy link
Contributor

No description provided.


var model = GetModelForApiKeys(currentUser);

Assert.True(model.PackageOwners.Any(o => o.Owner == currentUser.Username && o.CanPushNew));
Copy link
Member

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?

Copy link
Contributor Author

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));
Copy link
Member

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?

Copy link
Contributor Author

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));
Copy link
Member

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);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and yes

@scottbommarito
Copy link
Contributor Author

@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
Copy link
Member

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
Copy link
Member

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 };

Copy link
Member

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) { ... }
}

Copy link
Contributor Author

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));
Copy link
Member

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.

Copy link
Member

@joelverhagen joelverhagen left a 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 :shipit: .

@scottbommarito scottbommarito deleted the sb-test-apikeys branch July 22, 2019 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants