Skip to content

Commit dbf0b63

Browse files
fboucherCopilot
andcommitted
test: add SettingEndpoints edge-case tests (#104)
Co-authored-by: Copilot <[email protected]>
1 parent ad497e6 commit dbf0b63

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/NoteBookmark.Api.Tests/Endpoints/SettingEndpointsTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,62 @@ public async Task SettingsEndpoints_IntegrationFlow_WorksCorrectly()
170170
finalSettings.LastBookmarkDate.Should().Be(updatedSettings.LastBookmarkDate);
171171
}
172172

173+
[Fact]
174+
public async Task GetSettings_ReturnsDefaultPrompts_WithRequiredPlaceholders()
175+
{
176+
// Act
177+
var response = await _client.GetAsync("/api/settings/");
178+
179+
// Assert
180+
response.StatusCode.Should().Be(HttpStatusCode.OK);
181+
182+
var settings = await response.Content.ReadFromJsonAsync<Settings>();
183+
settings.Should().NotBeNull();
184+
settings!.SearchPrompt.Should().NotBeNullOrEmpty();
185+
settings.SearchPrompt.Should().Contain("{topic}");
186+
settings.SummaryPrompt.Should().NotBeNullOrEmpty();
187+
settings.SummaryPrompt.Should().Contain("{content}");
188+
}
189+
190+
[Fact]
191+
public async Task GetSettings_MasksAiApiKey_WhenKeyIsConfigured()
192+
{
193+
// Arrange — save settings that include an API key
194+
var settingsWithKey = CreateTestSettings();
195+
settingsWithKey.AiApiKey = "super-secret-api-key";
196+
var saveResponse = await _client.PostAsJsonAsync("/api/settings/SaveSettings", settingsWithKey);
197+
saveResponse.EnsureSuccessStatusCode();
198+
199+
// Act
200+
var response = await _client.GetAsync("/api/settings/");
201+
202+
// Assert
203+
response.StatusCode.Should().Be(HttpStatusCode.OK);
204+
205+
var settings = await response.Content.ReadFromJsonAsync<Settings>();
206+
settings.Should().NotBeNull();
207+
settings!.AiApiKey.Should().Be("********");
208+
}
209+
210+
[Fact]
211+
public async Task SaveSettings_WithEmptyPartitionKey_ReturnsBadRequest()
212+
{
213+
// Arrange
214+
var invalidSettings = new Settings
215+
{
216+
PartitionKey = "",
217+
RowKey = "setting",
218+
LastBookmarkDate = "2025-06-03T12:00:00",
219+
ReadingNotesCounter = "100"
220+
};
221+
222+
// Act
223+
var response = await _client.PostAsJsonAsync("/api/settings/SaveSettings", invalidSettings);
224+
225+
// Assert
226+
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
227+
}
228+
173229
// Helper methods
174230
private static Settings CreateTestSettings()
175231
{

0 commit comments

Comments
 (0)