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:
@@ -44,6 +44,33 @@ public class UserServiceTests
|
||||
Assert.Null(stats.NextLevelXp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatsAsync_ReturnsEnrollmentSlotStateAndRules()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
SeedLevelThresholds(db);
|
||||
var now = DateTime.UtcNow;
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local", Xp = 350 });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.AddRange(
|
||||
Lecture(1, now.AddDays(1)),
|
||||
Lecture(2, now.AddDays(2)),
|
||||
Lecture(3, now.AddDays(-1)));
|
||||
db.LectureEnrollments.AddRange(
|
||||
new LectureEnrollment { LectureId = 1, UserId = 1 },
|
||||
new LectureEnrollment { LectureId = 2, UserId = 1 },
|
||||
new LectureEnrollment { LectureId = 3, UserId = 1 });
|
||||
await db.SaveChangesAsync();
|
||||
var service = CreateService(db);
|
||||
|
||||
var stats = await service.GetStatsAsync(1);
|
||||
|
||||
Assert.Equal(3, stats.ActiveEnrollments);
|
||||
Assert.Equal(5, stats.EnrollmentSlotLimit);
|
||||
Assert.Equal(new[] { 1, 3, 4 }, stats.EnrollmentSlotRules.Select(rule => rule.Level));
|
||||
Assert.Equal(new[] { 3, 5, 7 }, stats.EnrollmentSlotRules.Select(rule => rule.Slots));
|
||||
}
|
||||
|
||||
private static AppDbContext CreateDbContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
@@ -77,4 +104,15 @@ public class UserServiceTests
|
||||
new LevelThreshold { Level = 3, RequiredXp = 300 });
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
private static Lecture Lecture(int id, DateTime startsAt) => new()
|
||||
{
|
||||
Id = id,
|
||||
CourseId = 1,
|
||||
Title = $"Lecture {id}",
|
||||
StartsAt = startsAt,
|
||||
EndsAt = startsAt.AddHours(2),
|
||||
IsOpen = true,
|
||||
MaxEnrollments = 30
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user