131 lines
4.6 KiB
C#
131 lines
4.6 KiB
C#
using DramaLing.Api.Tests.Integration.Fixtures;
|
|
using System.Net;
|
|
|
|
namespace DramaLing.Api.Tests.Integration.Controllers;
|
|
|
|
/// <summary>
|
|
/// OptionsVocabularyTestController 整合測試
|
|
/// 測試詞彙選項生成相關的 API 端點功能
|
|
/// </summary>
|
|
public class OptionsVocabularyTestControllerTests : IntegrationTestBase
|
|
{
|
|
public OptionsVocabularyTestControllerTests(DramaLingWebApplicationFactory factory) : base(factory)
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GenerateDistractors_WithValidParameters_ShouldReturnOptions()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
var queryParams = "?word=hello&level=A1&partOfSpeech=interjection&count=3";
|
|
|
|
// Act
|
|
var response = await client.GetAsync($"/api/options-vocabulary-test/generate-distractors{queryParams}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
content.Should().Contain("success");
|
|
content.Should().NotBeNullOrEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GenerateDistractors_WithMissingParameters_ShouldReturn400()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
var queryParams = "?word=hello"; // 缺少必要參數
|
|
|
|
// Act
|
|
var response = await client.GetAsync($"/api/options-vocabulary-test/generate-distractors{queryParams}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GenerateDistractors_WithoutAuth_ShouldReturn401()
|
|
{
|
|
// Arrange
|
|
var queryParams = "?word=hello&level=A1&partOfSpeech=noun&count=3";
|
|
|
|
// Act
|
|
var response = await HttpClient.GetAsync($"/api/options-vocabulary-test/generate-distractors{queryParams}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CheckSufficiency_WithValidData_ShouldReturnStatus()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
var queryParams = "?level=A1&partOfSpeech=noun";
|
|
|
|
// Act
|
|
var response = await client.GetAsync($"/api/options-vocabulary-test/check-sufficiency{queryParams}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
content.Should().Contain("success");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GenerateDistractorsDetailed_WithValidData_ShouldReturnDetailedOptions()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
var queryParams = "?word=beautiful&level=A2&partOfSpeech=adjective&count=4";
|
|
|
|
// Act
|
|
var response = await client.GetAsync($"/api/options-vocabulary-test/generate-distractors-detailed{queryParams}");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
content.Should().Contain("success");
|
|
content.Should().NotBeNullOrEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CoverageTest_ShouldReturnCoverageInfo()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
|
|
// Act
|
|
var response = await client.GetAsync("/api/options-vocabulary-test/coverage-test");
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
content.Should().Contain("success");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task VocabularyOptionsGeneration_ShouldBeConsistent()
|
|
{
|
|
// Arrange
|
|
var client = CreateTestUser1Client();
|
|
var word = "sophisticated";
|
|
var queryParams = $"?word={word}&level=C1&partOfSpeech=adjective&count=3";
|
|
|
|
// Act - 多次調用同一個端點
|
|
var response1 = await client.GetAsync($"/api/options-vocabulary-test/generate-distractors{queryParams}");
|
|
var response2 = await client.GetAsync($"/api/options-vocabulary-test/generate-distractors{queryParams}");
|
|
|
|
// Assert
|
|
response1.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
response2.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
|
|
var content1 = await response1.Content.ReadAsStringAsync();
|
|
var content2 = await response2.Content.ReadAsStringAsync();
|
|
|
|
// Mock 服務應該返回一致的格式(雖然內容可能不同)
|
|
content1.Should().Contain("success");
|
|
content2.Should().Contain("success");
|
|
}
|
|
} |