Skip to content

Commit

Permalink
3 tests failing due to cascading delete issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LokeSGJ committed Dec 9, 2024
1 parent 6e67c50 commit c4fb27a
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 158 deletions.
75 changes: 62 additions & 13 deletions Giraf.IntegrationTests/Endpoints/ActivityEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task GetAllActivities_ReturnsListOfActivities_WhenActivitiesExist()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

// Act
var response = await client.GetAsync("/weekplan");
Expand All @@ -47,7 +47,7 @@ public async Task GetAllActivities_ReturnsEmptyList_WhenNoActivitiesExist()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

// Act
var response = await client.GetAsync("/weekplan");
Expand All @@ -73,7 +73,7 @@ public async Task GetActivitiesForCitizenOnDate_ReturnsActivities_WhenActivities
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

// Act
int citizenId = seeder.Citizens[0].Id;
Expand All @@ -92,7 +92,13 @@ public async Task GetActivitiesForCitizenOnDate_ReturnsNotFound_WhenCitizenDoesN
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["admin"]);

var date = DateTime.UtcNow.Date.ToString("yyyy-MM-dd");
var nonExistentCitizenId = 999;

Expand All @@ -117,7 +123,7 @@ public async Task GetActivitiesForGradeOnDate_ReturnsActivities_WhenActivitiesEx
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

// Act
var date = DateTime.UtcNow.Date.ToString("yyyy-MM-dd");
Expand All @@ -136,7 +142,13 @@ public async Task GetActivitiesForGradeOnDate_ReturnsNotFound_WhenGradeDoesNotEx
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var date = DateTime.UtcNow.Date.ToString("yyyy-MM-dd");
var nonExistentGradeId = 999;

Expand All @@ -161,7 +173,7 @@ public async Task GetActivityById_ReturnsActivity_WhenActivityExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

int activityId = seeder.Activities[0].Id;

Expand All @@ -180,7 +192,13 @@ public async Task GetActivityById_ReturnsNotFound_WhenActivityDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var nonExistentActivityId = 999;

// Act
Expand All @@ -204,7 +222,7 @@ public async Task CreateActivityForCitizen_ReturnsCreated_WhenCitizenExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

int citizenId = seeder.Citizens[0].Id;
int pictogramId = seeder.Pictograms[0].Id;
Expand Down Expand Up @@ -233,7 +251,14 @@ public async Task CreateActivityForCitizen_ReturnsNotFound_WhenCitizenDoesNotExi
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);


var nonExistentCitizenId = 999;

var newActivityDto = new CreateActivityDTO
Expand Down Expand Up @@ -265,7 +290,7 @@ public async Task CreateActivityForGrade_ReturnsCreated_WhenGradeExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

int gradeId = seeder.Grades.First().Id;
int pictogramId = seeder.Pictograms.First().Id;
Expand Down Expand Up @@ -294,7 +319,13 @@ public async Task CreateActivityForGrade_ReturnsNotFound_WhenGradeDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var nonExistentGradeId = 999;

var newActivityDto = new CreateActivityDTO
Expand Down Expand Up @@ -326,7 +357,7 @@ public async Task UpdateActivity_ReturnsOk_WhenActivityExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

int activityId = seeder.Activities[0].Id;

Expand Down Expand Up @@ -361,7 +392,13 @@ public async Task UpdateActivity_ReturnsNotFound_WhenActivityDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var nonExistentActivityId = 999;

var newActivityDto = new CreateActivityDTO
Expand Down Expand Up @@ -393,7 +430,7 @@ public async Task DeleteActivity_ReturnsNoContent_WhenActivityExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

int activityId = seeder.Activities[0].Id;

Expand All @@ -417,7 +454,13 @@ public async Task DeleteActivity_ReturnsNotFound_WhenActivityDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var nonExistentActivityId = 999;

// Act
Expand All @@ -441,7 +484,7 @@ public async Task SetActivityCompletionStatus_ReturnsOk_WhenActivityExists()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

int activityId = seeder.Activities[0].Id;

Expand All @@ -468,7 +511,13 @@ public async Task SetActivityCompletionStatus_ReturnsNotFound_WhenActivityDoesNo
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["admin"]);

var nonExistentActivityId = 999;
var isComplete = true;

Expand All @@ -493,7 +542,7 @@ public async Task AssignPictogram_ReturnsOk_WhenActivityAndPictogramExist()
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

int activityId = seeder.Activities[0].Id;
int pictogramId = seeder.Pictograms[0].Id;
Expand Down Expand Up @@ -526,7 +575,7 @@ public async Task AssignPictogram_ReturnsNotFound_WhenActivityDoesNotExist()
seeder.SeedPictogram(scope.ServiceProvider.GetRequiredService<GirafDbContext>(), seeder.Organizations[0]);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["admin"]);

var nonExistentActivityId = 999;
int pictogramId = seeder.Pictograms[0].Id;
Expand Down Expand Up @@ -561,7 +610,7 @@ public async Task AssignPictogram_ReturnsNotFound_WhenPictogramDoesNotExist()
seeder.Pictograms[0]);
var client = factory.CreateClient();

TestAuthHandler.SetTestClaims(scope, seeder.Users["member"]);
client.AttachClaimsToken(scope, seeder.Users["member"]);

var nonExistentPictogramId = 999;
int activityId = seeder.Activities[0].Id;
Expand Down
17 changes: 16 additions & 1 deletion Giraf.IntegrationTests/Endpoints/CitizenEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ public async Task GetAllCitizens_ReturnsEmptyList_WhenNoCitizens()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

// Act
var response = await client.GetAsync("/citizens");

Expand Down Expand Up @@ -93,8 +98,13 @@ public async Task GetCitizenById_ReturnsNotFound_WhenCitizenDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

// Act
var response = await client.GetAsync("/citizens/999");

Expand Down Expand Up @@ -144,8 +154,13 @@ public async Task UpdateCitizen_ReturnsNotFound_WhenCitizenDoesNotExist()
{
// Arrange
var factory = new GirafWebApplicationFactory();
var seeder = new OnlyUsersAndOrgDb();
var scope = factory.Services.CreateScope();
factory.SeedDb(scope, seeder);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["member"]);

var updateCitizenDto = new UpdateCitizenDTO("FirstName", "LastName");

// Act
Expand Down Expand Up @@ -288,7 +303,7 @@ public async Task RemoveCitizen_ReturnsBadRequest_WhenCitizenNotInOrganization()
);
var client = factory.CreateClient();

client.AttachClaimsToken(scope, seeder.Users["admin"]);
client.AttachClaimsToken(scope, seeder.Users["owner"]);

var organizationId = seeder.Organizations[1].Id;
var citizenId = seeder.Citizens[0].Id;
Expand Down
Loading

0 comments on commit c4fb27a

Please sign in to comment.