forked from gongxuegit/tiku-backend.net
feat: add student video and profile experience
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Tiku.Api.Contracts;
|
||||
using Tiku.Application.Profile;
|
||||
using Tiku.Domain.Catalog;
|
||||
using Tiku.Domain.Common;
|
||||
using Tiku.Domain.Commerce;
|
||||
using Tiku.Domain.Identity;
|
||||
using Tiku.Domain.Learning;
|
||||
using Tiku.Domain.Operations;
|
||||
@@ -16,6 +19,11 @@ namespace Tiku.IntegrationTests.Api;
|
||||
|
||||
public sealed class ProfileEndpointTests
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web)
|
||||
{
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public async Task Logged_in_student_can_get_and_update_profile()
|
||||
{
|
||||
@@ -189,6 +197,59 @@ public sealed class ProfileEndpointTests
|
||||
Assert.Single(dbContext.ReportStatusEvents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Student_can_check_in_once_per_day_and_query_score_events()
|
||||
{
|
||||
await using var factory = new ApiTestFactory();
|
||||
var seed = await SeedStudentAsync(factory);
|
||||
await factory.SeedAsync(
|
||||
new StudentProfile
|
||||
{
|
||||
TenantId = seed.TenantId,
|
||||
UserId = seed.UserId
|
||||
},
|
||||
new PointActivityTask
|
||||
{
|
||||
TenantId = seed.TenantId,
|
||||
TaskKey = "daily_check_in",
|
||||
Title = "每日签到",
|
||||
TaskType = PointActivityTaskType.DailyLogin,
|
||||
Points = 5,
|
||||
MaxClaimsPerUser = 3650
|
||||
});
|
||||
using var client = factory.CreateClient();
|
||||
await LoginAsync(client, seed);
|
||||
|
||||
var firstResponse = await client.PostAsync("/api/profile/check-in", null);
|
||||
var first = await firstResponse.Content.ReadFromJsonAsync<CheckInResult>(JsonOptions);
|
||||
var secondResponse = await client.PostAsync("/api/profile/check-in", null);
|
||||
var second = await secondResponse.Content.ReadFromJsonAsync<CheckInResult>(JsonOptions);
|
||||
var eventsResponse = await client.GetAsync("/api/profile/score-events?sourceType=daily_check_in");
|
||||
var events = await eventsResponse.Content.ReadFromJsonAsync<ProfileScoreEventList>(JsonOptions);
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, firstResponse.StatusCode);
|
||||
Assert.False(first!.AlreadyCheckedIn);
|
||||
Assert.Equal(5, first.Points);
|
||||
Assert.Equal(HttpStatusCode.OK, secondResponse.StatusCode);
|
||||
Assert.True(second!.AlreadyCheckedIn);
|
||||
Assert.Equal(first.ScoreEventId, second.ScoreEventId);
|
||||
Assert.Equal(HttpStatusCode.OK, eventsResponse.StatusCode);
|
||||
var item = Assert.Single(events!.Items);
|
||||
Assert.Equal("check_in", item.EventType);
|
||||
Assert.Equal(5, item.Points);
|
||||
|
||||
using var scope = factory.CreateSystemScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
|
||||
Assert.Single(dbContext.PointActivityClaims.Where(claim =>
|
||||
claim.TenantId == seed.TenantId &&
|
||||
claim.UserId == seed.UserId &&
|
||||
claim.SourceType == "daily_check_in"));
|
||||
Assert.Single(dbContext.UserScoreEvents.Where(scoreEvent =>
|
||||
scoreEvent.TenantId == seed.TenantId &&
|
||||
scoreEvent.UserId == seed.UserId &&
|
||||
scoreEvent.SourceType == "daily_check_in"));
|
||||
}
|
||||
|
||||
private static async Task<(Guid TenantId, Guid UserId, string Phone)> SeedStudentAsync(ApiTestFactory factory)
|
||||
{
|
||||
var tenantId = Guid.NewGuid();
|
||||
|
||||
Reference in New Issue
Block a user