Add synced user notes
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using QuestionsApi.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace QuestionsApi.Tests;
|
||||
|
||||
public sealed class UserNotepadTests
|
||||
{
|
||||
[Fact]
|
||||
public void ValidatorAcceptsPlainTextAtMaximumLength()
|
||||
{
|
||||
var request = new UpdateUserNotepadRequest
|
||||
{
|
||||
Content = new string('x', UserNotepadValidator.MaxContentLength),
|
||||
ExpectedRevision = 0
|
||||
};
|
||||
|
||||
Assert.Null(UserNotepadValidator.Validate(request));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidatorRejectsOversizedContentAndNegativeRevision()
|
||||
{
|
||||
var oversized = new UpdateUserNotepadRequest
|
||||
{
|
||||
Content = new string('x', UserNotepadValidator.MaxContentLength + 1),
|
||||
ExpectedRevision = 0
|
||||
};
|
||||
Assert.Contains("characters or fewer", UserNotepadValidator.Validate(oversized));
|
||||
|
||||
var invalidRevision = new UpdateUserNotepadRequest { ExpectedRevision = -1 };
|
||||
Assert.Contains("cannot be negative", UserNotepadValidator.Validate(invalidRevision));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResponseDoesNotExposeUserOrMongoIdentifiers()
|
||||
{
|
||||
var response = UserNotepadResponse.FromModel(new UserNotepad
|
||||
{
|
||||
UserId = "private-user-id",
|
||||
Content = "My notes",
|
||||
Revision = 7
|
||||
});
|
||||
|
||||
Assert.Equal("My notes", response.Content);
|
||||
Assert.Equal(7, response.Revision);
|
||||
Assert.Null(typeof(UserNotepadResponse).GetProperty(nameof(UserNotepad.UserId)));
|
||||
Assert.Null(typeof(UserNotepadResponse).GetProperty(nameof(UserNotepad.Id)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user