@@ -44,4 +44,33 @@ public async Task SetReactions_OnlyWorksWithAllowedReactionSets()
4444 await reactWithNewInvalid . Should ( ) . ThrowAsync < ForbiddenException > ( ) ;
4545 reactions . Should ( ) . BeEquivalentTo ( thumbs ) ;
4646 }
47+
48+ [ Fact ( DisplayName = "Setting reactions overwrites existing reactions" ) ]
49+ public async Task SetReactions_OverwritesExistingReactions ( )
50+ {
51+ // Arrange
52+ await using var scope = _services . CreateAsyncScope ( ) ;
53+ var authorsRepository = scope . ServiceProvider . GetRequiredService < IAuthorsRepository > ( ) ;
54+ var discussionsRepository = scope . ServiceProvider . GetRequiredService < IDiscussionsRepository > ( ) ;
55+ var reactionsRepository = scope . ServiceProvider . GetRequiredService < IReactionsRepository > ( ) ;
56+
57+ var viewerId = Guid . NewGuid ( ) ;
58+ await authorsRepository . EnsureCreatedAsync ( viewerId ) ;
59+ var discussionId = await discussionsRepository . CreateAsync ( viewerId , "Title" , "Description" ) ;
60+
61+ // Act
62+ await reactionsRepository . SetAsync ( discussionId , viewerId , new HashSet < string > { "a" } ) ;
63+ await reactionsRepository . SetAsync ( discussionId , viewerId , new HashSet < string > { "a" , "b" } ) ;
64+ await reactionsRepository . SetAsync ( discussionId , viewerId , new HashSet < string > { "a" , "b" , "c" } ) ;
65+ await reactionsRepository . SetAsync ( discussionId , viewerId , new HashSet < string > { "b" , "d" } ) ;
66+
67+ // Assert
68+ var discussion = await discussionsRepository . GetByIdAsync ( discussionId , viewerId ) ;
69+ discussion . ViewerReactions . Should ( ) . BeEquivalentTo ( [ "b" , "d" ] ) ;
70+ discussion . ReactionCounters . Should ( ) . BeEquivalentTo ( new Dictionary < string , int >
71+ {
72+ { "b" , 1 } ,
73+ { "d" , 1 }
74+ } ) ;
75+ }
4776}
0 commit comments