Skip to content

Commit

Permalink
Greatly simplify test output of failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Nov 19, 2024
1 parent e037ab9 commit f1747b2
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions backend/Testing/LexCore/Services/UserServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,21 @@ public Task DisposeAsync()
return _lexBoxDbContext.SaveChangesAsync();
}

public void UserListShouldBe(IEnumerable<User> actual, IEnumerable<User?> expected)

Check warning on line 88 in backend/Testing/LexCore/Services/UserServiceTest.cs

View workflow job for this annotation

GitHub Actions / Build API / publish-api

Public method 'UserListShouldBe' on test class 'UserServiceTest' should be marked as a Theory. Reduce the visibility of the method, or add a Theory attribute to the method. (https://xunit.net/xunit.analyzers/rules/xUnit1013)
{
var actualNames = actual.Select(u => u.Name);
var expectedNames = expected.Select(u => u?.Name ?? "<null name>");
actualNames.Should().BeEquivalentTo(expectedNames, options => options.WithoutStrictOrdering());
}

[Fact]
public async Task ManagerCanSeeAllUsersEvenInConfidentialProjects()
{
// Robin Hood is in Outlaws org (admin) and Sherwood project (private, manager)
var authUser = new LexAuthUser(Robin!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
// John, who is in both the Outlaws org (user) and Sherwood project (member) is not duplicated
users.Should().BeEquivalentTo([Robin, Marian, John, Tuck], options => options.WithoutStrictOrdering());
UserListShouldBe(users, [Robin, Marian, John, Tuck]);
}

[Fact]
Expand All @@ -102,7 +109,7 @@ public async Task NonManagerCanNotSeeUsersInConfidentialProjects()
var authUser = new LexAuthUser(John!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
// John can see Robin because he shares an org, but not Marian even though she's a manager of the Sherwood project
users.Should().BeEquivalentTo([Robin, John], options => options.WithoutStrictOrdering());
UserListShouldBe(users, [Robin, John]);
}

[Fact]
Expand All @@ -112,7 +119,7 @@ public async Task ManagerOfOneProjectAndMemberOfAnotherPublicProjectCanSeeUsersI
var authUser = new LexAuthUser(Marian!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
// Marian can see everyone in both projects; Tuck is not duplicated despite being in both projects
users.Should().BeEquivalentTo([Robin, Marian, John, Tuck, Sheriff], options => options.WithoutStrictOrdering());
UserListShouldBe(users, [Robin, Marian, John, Tuck, Sheriff]);
}

[Fact]
Expand All @@ -126,7 +133,7 @@ public async Task ManagerOfOneProjectAndMemberOfAnotherConfidentialProjectCanNot
// ... but can still only see the users in Nottingham and LawEnforcement
var authUser = new LexAuthUser(Sheriff!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
users.Should().BeEquivalentTo([Sheriff, Guy, Marian, Tuck], options => options.WithoutStrictOrdering());
UserListShouldBe(users, [Sheriff, Guy, Marian, Tuck]);
}
finally
{
Expand All @@ -140,7 +147,8 @@ public async Task OrgAdminsInNoProjectsCanSeeOnlyTheirOrg()
// Bishop of Hereford is in Church org (admin) but no projects
var authUser = new LexAuthUser(Bishop!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
users.Should().BeEquivalentTo([Bishop, Tuck], options => options.WithoutStrictOrdering());
// Bishop can only see members of Church org
UserListShouldBe(users, [Bishop, Tuck]);
}

[Fact]
Expand All @@ -149,7 +157,8 @@ public async Task OrgMembersInNoProjectsCanSeeOnlyTheirOrg()
// Guy of Gisborne is in LawEnforcement org (user) but no projects
var authUser = new LexAuthUser(Guy!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
users.Should().BeEquivalentTo([Sheriff, Guy], options => options.WithoutStrictOrdering());
// Guy can only see members of LawEnforcement org
UserListShouldBe(users, [Sheriff, Guy]);
}

[Fact]
Expand All @@ -159,7 +168,7 @@ public async Task OrgAndProjectMembersCanSeeFellowOrgMembersAndFellowPublicProje
var authUser = new LexAuthUser(Tuck!);
var users = await _userService.UserQueryForTypeahead(authUser).ToArrayAsync();
// Tuck can see everyone in Church and Nottingham, but nobody in Sherwood because it's private — though he can see Marian because he shares a public project with her
users.Should().BeEquivalentTo([Bishop, Tuck, Sheriff, Marian], options => options.WithoutStrictOrdering());
UserListShouldBe(users, [Bishop, Tuck, Sheriff, Marian]);
}

private User CreateUser(string name)
Expand Down

0 comments on commit f1747b2

Please sign in to comment.