feat: добавил ограничение записи на лекции
Backend CI / build-and-test (push) Failing after 32s
Frontend CI / build-and-check (push) Failing after 5m5s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 6s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 1m28s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 19s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Has been skipped
Backend CI / build-and-test (push) Failing after 32s
Frontend CI / build-and-check (push) Failing after 5m5s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 6s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 1m28s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 19s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Has been skipped
This commit is contained in:
@@ -4,6 +4,7 @@ using UniVerse.Application.DTOs.Lectures;
|
||||
using UniVerse.Application.DTOs.Notifications;
|
||||
using UniVerse.Application.Interfaces;
|
||||
using UniVerse.Domain.Entities;
|
||||
using UniVerse.Domain.Exceptions;
|
||||
using UniVerse.Infrastructure.Data;
|
||||
using UniVerse.Infrastructure.Services;
|
||||
using Xunit;
|
||||
@@ -92,6 +93,79 @@ public class LectureServiceTests
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 3)]
|
||||
[InlineData(2, 3)]
|
||||
[InlineData(3, 5)]
|
||||
[InlineData(4, 7)]
|
||||
[InlineData(5, 7)]
|
||||
public async Task EnrollAsync_ThrowsWhenActiveEnrollmentLimitReached(int level, int activeEnrollments)
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var gamification = Substitute.For<IGamificationService>();
|
||||
gamification.CalculateLevelAsync(Arg.Any<int>()).Returns(level);
|
||||
var service = new LectureService(db, gamification, Substitute.For<INotificationScheduler>());
|
||||
var startsAt = DateTime.UtcNow.AddDays(1);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(100, startsAt.AddDays(100)));
|
||||
for (var i = 1; i <= activeEnrollments; i++)
|
||||
{
|
||||
db.Lectures.Add(Lecture(i, startsAt.AddDays(i)));
|
||||
db.LectureEnrollments.Add(new LectureEnrollment { LectureId = i, UserId = 1 });
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await Assert.ThrowsAsync<ConflictException>(() => service.EnrollAsync(100, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnrollAsync_ThrowsWhenPastUnattendedEnrollmentsReachLimit()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var gamification = Substitute.For<IGamificationService>();
|
||||
gamification.CalculateLevelAsync(Arg.Any<int>()).Returns(1);
|
||||
var service = new LectureService(db, gamification, Substitute.For<INotificationScheduler>());
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(100, now.AddDays(1)));
|
||||
for (var i = 1; i <= 3; i++)
|
||||
{
|
||||
db.Lectures.Add(Lecture(i, now.AddDays(-i)));
|
||||
db.LectureEnrollments.Add(new LectureEnrollment { LectureId = i, UserId = 1 });
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await Assert.ThrowsAsync<ConflictException>(() => service.EnrollAsync(100, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnrollAsync_DoesNotCountAttendedEnrollmentsTowardLimit()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var gamification = Substitute.For<IGamificationService>();
|
||||
gamification.CalculateLevelAsync(Arg.Any<int>()).Returns(1);
|
||||
var service = new LectureService(db, gamification, Substitute.For<INotificationScheduler>());
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(100, now.AddDays(1)));
|
||||
for (var i = 1; i <= 3; i++)
|
||||
{
|
||||
db.Lectures.Add(Lecture(i, now.AddDays(-i)));
|
||||
db.LectureEnrollments.Add(new LectureEnrollment { LectureId = i, UserId = 1, Attended = true });
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await service.EnrollAsync(100, 1);
|
||||
|
||||
Assert.True(await db.LectureEnrollments.AnyAsync(e => e.LectureId == 100 && e.UserId == 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnenrollAsync_CancelsLectureReminders()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user