Allow teachers to provision Moodle courses
This commit is contained in:
1 parent
d5573ee4cb
commit
6d70f6a385
8 files changed
+102
-11
No files matched your search
@@ -4,9 +4,11 @@ using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Jiaowu.Api.Infrastructure.Teaching;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
@@ -83,6 +85,8 @@ public sealed class TeachingTaskRosterProfileTests
|
||||
db.Add(task);
|
||||
db.Add(new TeachingTask { TaskNumber = "OTHER", Name = "其他教学班", AcademicTermId = term.Id, CourseId = course.Id, Capacity = 40, Status = TeachingTaskStatus.Published, MoodleCourseUrl = "https://moodle.example.edu/course/view.php?id=99" });
|
||||
db.Add(new TeachingTask { TaskNumber = "DRAFT", Name = "草稿教学班", AcademicTermId = term.Id, CourseId = course.Id, Capacity = 40, Status = TeachingTaskStatus.Draft, MoodleCourseUrl = "https://moodle.example.edu/course/view.php?id=100", Classes = [new TeachingTaskClass { AdministrativeClassId = administrativeClass.Id }] });
|
||||
var teacherTask = new TeachingTask { TaskNumber = "OWN", Name = "本人教学班", AcademicTermId = term.Id, CourseId = course.Id, Capacity = 40, Status = TeachingTaskStatus.Published, Teachers = [new TeachingTaskTeacher { TeacherId = teacher.Id }] };
|
||||
db.Add(teacherTask);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var studentController = new CourseSelectionsController(db, new StudentDataScope(studentUser.Id));
|
||||
@@ -91,6 +95,15 @@ public sealed class TeachingTaskRosterProfileTests
|
||||
var ownCourse = Assert.Single(courses.Cast<object>());
|
||||
Assert.Equal("https://moodle.example.edu/course/view.php?id=42", Property(ownCourse, "MoodleCourseUrl"));
|
||||
|
||||
var moodle = new MoodleCourseClient(new UnusedHttpClientFactory(), new ConfigurationBuilder().Build());
|
||||
var moodleController = new MoodleCoursesController(db, new TeacherDataScope(teacherUser.Id), moodle);
|
||||
var otherTask = await db.TeachingTasks.SingleAsync(x => x.TaskNumber == "OTHER");
|
||||
Assert.IsType<ForbidResult>(await moodleController.Create(otherTask.Id, CancellationToken.None));
|
||||
Assert.IsType<ForbidResult>(await moodleController.SyncTeachers(otherTask.Id, CancellationToken.None));
|
||||
Assert.Equal(502, Assert.IsType<ObjectResult>(await moodleController.Create(teacherTask.Id, CancellationToken.None)).StatusCode);
|
||||
Assert.IsType<ForbidResult>(await moodleController.Copy(teacherTask.Id, new MoodleCopyRequest(99), CancellationToken.None));
|
||||
Assert.Equal(502, Assert.IsType<ObjectResult>(await moodleController.SyncTeachers(task.Id, CancellationToken.None)).StatusCode);
|
||||
|
||||
var controller = new CourseSelectionsController(
|
||||
db,
|
||||
new TeacherDataScope(teacherUser.Id));
|
||||
@@ -134,4 +147,9 @@ public sealed class TeachingTaskRosterProfileTests
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(userId, "学生", null, DataScope.Self, new HashSet<string> { SystemRoles.Student });
|
||||
}
|
||||
|
||||
private sealed class UnusedHttpClientFactory : IHttpClientFactory
|
||||
{
|
||||
public HttpClient CreateClient(string name) => throw new InvalidOperationException("HTTP should not be called");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user