Skip to content

Commit

Permalink
Forced all integration tests to run sequentially instead of in parall…
Browse files Browse the repository at this point in the history
…el. It takes much longer to run the test suite (about 25 seconds), but the results are consistent
  • Loading branch information
LokeSGJ committed Dec 5, 2024
1 parent eadb78c commit a81ffe7
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class ActivityEndpointTests
{
#region GET /weekplan/ - Get all activities
Expand Down
1 change: 1 addition & 0 deletions Giraf.IntegrationTests/Endpoints/CitizensEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class CitizensEndpointTests
{
#region Get All Citizens Tests
Expand Down
27 changes: 25 additions & 2 deletions Giraf.IntegrationTests/Endpoints/GradeEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class GradeEndpointsTests
{
#region 1. Get Grade by ID Tests
Expand All @@ -22,10 +23,19 @@ public async Task GetGradeById_ReturnsGrade_WhenGradeExists()
var factory = new GirafWebApplicationFactory(_ => new BasicGradeSeeder());
var client = factory.CreateClient();

var testOrgId = 1;
int orgId;
using (var scope = factory.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<GirafDbContext>();
var organization = await dbContext.Organizations.FirstOrDefaultAsync();
Assert.NotNull(organization);
orgId = organization.Id;
}

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim("OrgMember", testOrgId.ToString())
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", orgId.ToString())
};

int gradeId;
Expand Down Expand Up @@ -59,6 +69,7 @@ public async Task GetGradeById_ReturnsNotFound_WhenGradeDoesNotExist()
var testOrgId = 1;
TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", testOrgId.ToString())
};

Expand Down Expand Up @@ -92,6 +103,7 @@ public async Task GetGradesInOrganization_ReturnsGrades_WhenOrganizationExists()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", organizationId.ToString())
};

Expand All @@ -116,6 +128,7 @@ public async Task GetGradesInOrganization_ReturnsNotFound_WhenOrganizationDoesNo

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", nonExistentOrganizationId.ToString())
};

Expand Down Expand Up @@ -149,6 +162,7 @@ public async Task CreateGrade_ReturnsCreated_WhenOrganizationExists()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgAdmin", organizationId.ToString())
};

Expand Down Expand Up @@ -178,6 +192,7 @@ public async Task CreateGrade_ReturnsForbidden_WhenOrganizationDoesNotExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", nonExistentOrganizationId.ToString())
};

Expand Down Expand Up @@ -207,6 +222,7 @@ public async Task ChangeGradeName_ReturnsOk_WhenGradeExists()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgAdmin", "1")
};

Expand Down Expand Up @@ -243,6 +259,7 @@ public async Task ChangeGradeName_ReturnsForbidden_WhenGradeDoesNotExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand All @@ -267,6 +284,7 @@ public async Task AddCitizensToGrade_ReturnsOk_WhenGradeAndCitizensExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand Down Expand Up @@ -309,6 +327,7 @@ public async Task AddCitizensToGrade_ReturnsNotFound_WhenGradeDoesNotExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand Down Expand Up @@ -347,6 +366,7 @@ public async Task RemoveCitizensFromGrade_ReturnsOk_WhenGradeAndCitizensExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand Down Expand Up @@ -386,6 +406,7 @@ public async Task RemoveCitizensFromGrade_ReturnsNotFound_WhenGradeDoesNotExist(

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand Down Expand Up @@ -424,6 +445,7 @@ public async Task DeleteGrade_ReturnsNoContent_WhenGradeExists()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgAdmin", "1")
};

Expand Down Expand Up @@ -462,6 +484,7 @@ public async Task DeleteGrade_ReturnsForbidden_WhenGradeDoesNotExist()

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", "1")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class InvitationEndpointsTests
{
#region Get Invitation by ID Tests - Test 1-4
Expand Down
1 change: 1 addition & 0 deletions Giraf.IntegrationTests/Endpoints/LoginEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class LoginEndpointTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class OrganizationEndpointsTests
{
#region Get Organizations for User Tests
Expand Down Expand Up @@ -80,6 +81,12 @@ public async Task GetOrganizationById_ReturnsOrganization_WhenOrganizationExists
Assert.NotNull(organization);
organizationId = organization.Id;
}

TestAuthHandler.TestClaims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, "testUserId"),
new Claim("OrgMember", organizationId.ToString())
};

// Act
var response = await client.GetAsync($"/organizations/{organizationId}");
Expand All @@ -99,7 +106,7 @@ public async Task GetOrganizationById_ReturnsNotFound_WhenOrganizationDoesNotExi
var factory = new GirafWebApplicationFactory(_ => new EmptyDb());
var client = factory.CreateClient();

var nonExistentOrganizationId = 9999;
var nonExistentOrganizationId = 1;
var testUserId = "test-user-id";

// Set up the test claims
Expand Down
1 change: 1 addition & 0 deletions Giraf.IntegrationTests/Endpoints/PictogramEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class PictogramEndpointsTests
{
#region Create Pictogram Tests
Expand Down
1 change: 1 addition & 0 deletions Giraf.IntegrationTests/Endpoints/UsersEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Giraf.IntegrationTests.Endpoints
{
[Collection("IntegrationTests")]
public class UsersEndpointTests
{
#region Create User Tests
Expand Down

0 comments on commit a81ffe7

Please sign in to comment.