feat: добавил напоминания о лекциях
Backend CI / build-and-test (push) Successful in 51s
Frontend CI / build-and-check (push) Failing after 5m11s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 14s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m20s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 23s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 11s
Backend CI / build-and-test (push) Successful in 51s
Frontend CI / build-and-check (push) Failing after 5m11s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 14s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 1m20s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 23s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 11s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NSubstitute;
|
||||
using UniVerse.Application.DTOs.Lectures;
|
||||
using UniVerse.Application.DTOs.Notifications;
|
||||
using UniVerse.Application.Interfaces;
|
||||
using UniVerse.Domain.Entities;
|
||||
using UniVerse.Infrastructure.Data;
|
||||
@@ -15,7 +16,7 @@ public class LectureServiceTests
|
||||
public async Task GetAllAsync_MarksLecturesEnrolledByCurrentUser()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>());
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>(), Substitute.For<INotificationScheduler>());
|
||||
var startsAt = DateTime.UtcNow.AddDays(1);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
@@ -32,6 +33,86 @@ public class LectureServiceTests
|
||||
Assert.False(result.Items.Single(item => item.Id == 2).IsEnrolled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnrollAsync_SchedulesLectureReminders()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var scheduler = Substitute.For<INotificationScheduler>();
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>(), scheduler);
|
||||
var startsAt = DateTime.UtcNow.AddHours(4);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local", DisplayName = "Student" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(1, startsAt));
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await service.EnrollAsync(1, 1);
|
||||
|
||||
await scheduler.Received(1).ScheduleAsync(
|
||||
Arg.Is<NotificationMessage>(m => m.Recipient == "student@test.local" && m.Subject.Contains("через 3 часа")),
|
||||
Arg.Is<DateTimeOffset>(d => d == new DateTimeOffset(startsAt.AddHours(-3))),
|
||||
"lecture-1-user-1-starts-in-3-hours",
|
||||
Arg.Any<CancellationToken>());
|
||||
await scheduler.Received(1).ScheduleAsync(
|
||||
Arg.Is<NotificationMessage>(m => m.Recipient == "student@test.local" && m.Subject.Contains("через 1 час")),
|
||||
Arg.Is<DateTimeOffset>(d => d == new DateTimeOffset(startsAt.AddHours(-1))),
|
||||
"lecture-1-user-1-starts-in-1-hour",
|
||||
Arg.Any<CancellationToken>());
|
||||
await scheduler.Received(1).ScheduleAsync(
|
||||
Arg.Is<NotificationMessage>(m => m.Recipient == "student@test.local" && m.Subject.Contains("Оцените")),
|
||||
Arg.Is<DateTimeOffset>(d => d == new DateTimeOffset(startsAt.AddHours(2))),
|
||||
"lecture-1-user-1-ended",
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnrollAsync_SkipsPastLectureReminders()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var scheduler = Substitute.For<INotificationScheduler>();
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>(), scheduler);
|
||||
var startsAt = DateTime.UtcNow.AddMinutes(90);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(1, startsAt));
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await service.EnrollAsync(1, 1);
|
||||
|
||||
await scheduler.DidNotReceive().ScheduleAsync(
|
||||
Arg.Any<NotificationMessage>(),
|
||||
Arg.Any<DateTimeOffset>(),
|
||||
"lecture-1-user-1-starts-in-3-hours",
|
||||
Arg.Any<CancellationToken>());
|
||||
await scheduler.Received(2).ScheduleAsync(
|
||||
Arg.Any<NotificationMessage>(),
|
||||
Arg.Any<DateTimeOffset>(),
|
||||
Arg.Any<string>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnenrollAsync_CancelsLectureReminders()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var scheduler = Substitute.For<INotificationScheduler>();
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>(), scheduler);
|
||||
var startsAt = DateTime.UtcNow.AddHours(4);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.Add(Lecture(1, startsAt));
|
||||
db.LectureEnrollments.Add(new LectureEnrollment { LectureId = 1, UserId = 1 });
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await service.UnenrollAsync(1, 1);
|
||||
|
||||
await scheduler.Received(1).CancelAsync("lecture-1-user-1-starts-in-3-hours", Arg.Any<CancellationToken>());
|
||||
await scheduler.Received(1).CancelAsync("lecture-1-user-1-starts-in-1-hour", Arg.Any<CancellationToken>());
|
||||
await scheduler.Received(1).CancelAsync("lecture-1-user-1-ended", Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
private static AppDbContext CreateDbContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
|
||||
Reference in New Issue
Block a user