feat: перелопатил синхронизацию преподавателей
Backend CI / build-and-test (push) Failing after 13m11s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Failing after 10m12s
Frontend CI / build-and-check (push) Failing after 16m9s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 14m6s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 14m58s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Failing after 14m58s
Backend CI / build-and-test (push) Failing after 13m11s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Failing after 10m12s
Frontend CI / build-and-check (push) Failing after 16m9s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Failing after 14m6s
🚀 Create and publish a Docker image / Build & publish backend image (push) Failing after 14m58s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Failing after 14m58s
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NSubstitute;
|
||||
using UniVerse.Application.DTOs.Reviews;
|
||||
using UniVerse.Application.DTOs.Common;
|
||||
using UniVerse.Application.Interfaces;
|
||||
using UniVerse.Domain.Entities;
|
||||
using UniVerse.Domain.Enums;
|
||||
using UniVerse.Domain.Exceptions;
|
||||
using UniVerse.Infrastructure.Data;
|
||||
using UniVerse.Infrastructure.Services;
|
||||
using Xunit;
|
||||
@@ -65,6 +67,29 @@ public class ReviewServiceTests
|
||||
await queue.Received(1).EnqueueAsync(1, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByLectureAsync_TeacherCannotReadAnotherTeachersReviews()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var service = CreateService(db, Substitute.For<IReviewAnalysisQueue>());
|
||||
await SeedAnalyzedReviewAsync(db, teacherId: 2);
|
||||
|
||||
await Assert.ThrowsAsync<ForbiddenException>(() =>
|
||||
service.GetByLectureAsync(1, new PaginationRequest(), currentUserId: 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetByLectureAsync_AdminCanReadAnyLectureReviews()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var service = CreateService(db, Substitute.For<IReviewAnalysisQueue>());
|
||||
await SeedAnalyzedReviewAsync(db, teacherId: 2);
|
||||
|
||||
var result = await service.GetByLectureAsync(1, new PaginationRequest(), currentUserId: 1, isAdmin: true);
|
||||
|
||||
Assert.Single(result.Items);
|
||||
}
|
||||
|
||||
private static ReviewService CreateService(AppDbContext db, IReviewAnalysisQueue queue)
|
||||
{
|
||||
var gamification = Substitute.For<IGamificationService>();
|
||||
@@ -72,7 +97,7 @@ public class ReviewServiceTests
|
||||
return new ReviewService(db, gamification, queue);
|
||||
}
|
||||
|
||||
private static async Task SeedLectureAsync(AppDbContext db)
|
||||
private static async Task SeedLectureAsync(AppDbContext db, int? teacherId = null)
|
||||
{
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local", DisplayName = "Student" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
@@ -80,6 +105,7 @@ public class ReviewServiceTests
|
||||
{
|
||||
Id = 1,
|
||||
CourseId = 1,
|
||||
TeacherId = teacherId,
|
||||
Title = "Lecture",
|
||||
StartsAt = DateTime.UtcNow.AddDays(-1),
|
||||
EndsAt = DateTime.UtcNow.AddDays(-1).AddHours(2),
|
||||
@@ -89,9 +115,9 @@ public class ReviewServiceTests
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static async Task SeedAnalyzedReviewAsync(AppDbContext db)
|
||||
private static async Task SeedAnalyzedReviewAsync(AppDbContext db, int? teacherId = null)
|
||||
{
|
||||
await SeedLectureAsync(db);
|
||||
await SeedLectureAsync(db, teacherId);
|
||||
db.Reviews.Add(new Review
|
||||
{
|
||||
Id = 1,
|
||||
|
||||
Reference in New Issue
Block a user