Skip to content

Commit

Permalink
Merge pull request #67 from ZaqueuCavalcante/66-finalize-class-tests
Browse files Browse the repository at this point in the history
Finalize class tests
  • Loading branch information
ZaqueuCavalcante authored Oct 19, 2024
2 parents bb887bf + 579e8dd commit 4272d25
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/pr.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ jobs:
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
indicators: true
format: markdown
output: both
format: markdown
indicators: true
thresholds: '55 55'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public async Task<OneOf<SykiSuccess, SykiError>> Finalize(Guid institutionId, Fi
.Include(x => x.Lessons)
.ThenInclude(x => x.Attendances)
.Include(x => x.Students)
.Include(t => t.ExamGrades)
.Where(c => c.InstitutionId == institutionId && data.Classes.Contains(c.Id))
.ToListAsync();

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ O módulo acadêmico conta com:

## Overview

Se cadastre em https://syki.zaqbit.com e teste o sistema em produção.
Se cadastre em https://app.syki.com.br e teste o sistema em produção.

<img src="./Docs/images/syki_overview.gif" style="border-radius: 6px">
5 changes: 3 additions & 2 deletions Tests/Clients/AcademicHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Syki.Front.Features.Academic.CreateStudent;
using Syki.Front.Features.Academic.CreateTeacher;
using Syki.Front.Features.Academic.GetDisciplines;
using Syki.Front.Features.Academic.FinalizeClasses;
using Syki.Front.Features.Academic.CreateDiscipline;
using Syki.Front.Features.Academic.GetNotifications;
using Syki.Front.Features.Academic.GetAcademicClass;
Expand Down Expand Up @@ -283,8 +284,8 @@ public async Task<OneOf<SuccessOut, ErrorOut>> StartClasses(List<Guid> classes)

public async Task<OneOf<SuccessOut, ErrorOut>> FinalizeClasses(List<Guid> classes)
{
var client = new StartClassesClient(Http);
return await client.Start(classes);
var client = new FinalizeClassesClient(Http);
return await client.Finalize(classes);
}

public async Task<BasicInstitutionTestDto> CreateBasicInstitutionData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,38 @@ public async Task Should_finalize_class()
// Arrange
var academicClient = await _back.LoggedAsAcademic();
var data = await academicClient.CreateBasicInstitutionData();
var period = data.AcademicPeriod2.Id;

await academicClient.CreateEnrollmentPeriod(period, -2, 2);

TeacherOut chico = await academicClient.CreateTeacher("Chico");
StudentOut student = await academicClient.CreateStudent(data.AdsCourseOffering.Id, "Zaqueu");
ClassOut mathClass = await academicClient.CreateClass(data.AdsDisciplines.DiscreteMath.Id, chico.Id, period, 40, [ new(Day.Monday, Hour.H07_00, Hour.H10_00) ]);

await academicClient.ReleaseClassesForEnrollment([mathClass.Id]);
await academicClient.AddStartedAdsClasses(data, _back);

var studentClient = await _back.LoggedAsStudent(student.Email);
await studentClient.CreateStudentEnrollment([mathClass.Id]);
var teacherClient = await _back.LoggedAsTeacher(data.Teacher.Email);
var lessons = data.AdsClasses.HumanMachineInteractionDesign.Lessons;

await academicClient.UpdateEnrollmentPeriod(period, -2, -1);


foreach (var lesson in lessons)
{
await teacherClient.CreateLessonAttendance(lesson.Id, [data.Student.Id]);
}

// Act
await academicClient.StartClasses([mathClass.Id]);
var response = await academicClient.FinalizeClasses([data.AdsClasses.HumanMachineInteractionDesign.Id]);

// Assert
await using var ctx = _back.GetDbContext();
var examGrades = await ctx.ExamGrades.Where(x => x.ClassId == mathClass.Id).ToListAsync();

examGrades.Should().HaveCount(3);
examGrades.Should().AllSatisfy(x => x.StudentId.Should().Be(student.Id));
examGrades.Count(x => x.ExamType == ExamType.N1).Should().Be(1);
examGrades.Count(x => x.ExamType == ExamType.N2).Should().Be(1);
examGrades.Count(x => x.ExamType == ExamType.N3).Should().Be(1);
examGrades.Should().AllSatisfy(x => x.Note.Should().Be(0));
response.ShouldBeSuccess();
}

[Test]
public async Task Should_not_start_invalid_classes2()
public async Task Should_not_finalize_invalid_classes_list()
{
// Arrange
var academicClient = await _back.LoggedAsAcademic();

// Act
var response = await academicClient.StartClasses([Guid.NewGuid()]);
var response = await academicClient.FinalizeClasses([Guid.NewGuid()]);

// Assert
response.ShouldBeError(new InvalidClassesList());
}

[Test]
public async Task Should_not_start_on_pre_enrollment_class2()
public async Task Should_not_finalize_on_pre_enrollment_class()
{
// Arrange
var academicClient = await _back.LoggedAsAcademic();
Expand All @@ -65,14 +50,14 @@ public async Task Should_not_start_on_pre_enrollment_class2()
ClassOut mathClass = await academicClient.CreateClass(data.AdsDisciplines.DiscreteMath.Id, chico.Id, period, 40, [ new(Day.Monday, Hour.H07_00, Hour.H10_00) ]);

// Act
var response = await academicClient.StartClasses([mathClass.Id]);
var response = await academicClient.FinalizeClasses([mathClass.Id]);

// Assert
response.ShouldBeError(new ClassMustHaveOnEnrollmentStatus());
response.ShouldBeError(new ClassMustHaveStartedStatus());
}

[Test]
public async Task Should_not_start_on_enrollment_class_when_enrollment_period_is_not_finalize2d()
public async Task Should_not_finalize_on_enrollment_class()
{
// Arrange
var academicClient = await _back.LoggedAsAcademic();
Expand All @@ -87,9 +72,24 @@ public async Task Should_not_start_on_enrollment_class_when_enrollment_period_is
await academicClient.ReleaseClassesForEnrollment([mathClass.Id]);

// Act
var response = await academicClient.StartClasses([mathClass.Id]);
var response = await academicClient.FinalizeClasses([mathClass.Id]);

// Assert
response.ShouldBeError(new ClassMustHaveStartedStatus());
}

[Test]
public async Task Should_not_finalize_classes_with_pending_lessons()
{
// Arrange
var academicClient = await _back.LoggedAsAcademic();
var data = await academicClient.CreateBasicInstitutionData();
await academicClient.AddStartedAdsClasses(data, _back);

// Act
var response = await academicClient.FinalizeClasses([data.AdsClasses.HumanMachineInteractionDesign.Id]);

// Assert
response.ShouldBeError(new EnrollmentPeriodMustBeFinalized());
response.ShouldBeError(new AllClassLessonsMustHaveFinalizedStatus());
}
}

0 comments on commit 4272d25

Please sign in to comment.