-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR implements the ability to rate profile and level comments through the game API. Closes #70 ![image](https://github.com/LittleBigRefresh/Refresh/assets/51852312/17be559d-d3f4-4af8-aac2-e7529f2bd5ff)
- Loading branch information
Showing
9 changed files
with
211 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using MongoDB.Bson; | ||
using Realms; | ||
using Refresh.GameServer.Types.Comments; | ||
using Refresh.GameServer.Types.Reviews; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Types.Relations; | ||
#nullable disable | ||
|
||
public partial class CommentRelation : IRealmObject | ||
{ | ||
public ObjectId CommentRelationId { get; set; } = ObjectId.GenerateNewId(); | ||
public GameUser User { get; set; } | ||
public GameComment Comment { get; set; } | ||
[Ignored] | ||
public RatingType RatingType | ||
{ | ||
get => (RatingType)this._RatingType; | ||
set => this._RatingType = (int)value; | ||
} | ||
|
||
// ReSharper disable once InconsistentNaming | ||
internal int _RatingType { get; set; } | ||
public DateTimeOffset Timestamp { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Refresh.GameServer.Types.Comments; | ||
using Refresh.GameServer.Types.Lists; | ||
using Refresh.GameServer.Types.Reviews; | ||
using Refresh.GameServer.Types.UserData; | ||
using RefreshTests.GameServer.Extensions; | ||
using TokenType = Refresh.GameServer.Authentication.TokenType; | ||
|
||
namespace RefreshTests.GameServer.Tests.Comments; | ||
|
||
public class CommentTests : GameServerTest | ||
{ | ||
public static void RateComment(TestContext context, GameUser user, GameComment comment, string rateCommentUrl, string getCommentsUrl) | ||
{ | ||
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user); | ||
|
||
|
||
foreach (RatingType ratingType in new List<RatingType> {RatingType.Neutral, RatingType.Boo, RatingType.Yay}) | ||
{ | ||
for (int i = 0; i < 3; i++) // Rate multiple times to test that duplicate ratings are not added | ||
{ | ||
// ReSharper disable once RedundantAssignment | ||
client.PostAsync($"{rateCommentUrl}?commentId={comment.SequentialId}&rating={ratingType.ToDPad()}", null); | ||
} | ||
|
||
HttpResponseMessage response = client.GetAsync(getCommentsUrl).Result; | ||
SerializedCommentList userComments = response.Content.ReadAsXML<SerializedCommentList>(); | ||
comment = userComments.Items.First(); | ||
|
||
int expectedThumbsUp, expectedThumbsDown; | ||
|
||
switch (ratingType) | ||
{ | ||
case RatingType.Neutral: | ||
expectedThumbsDown = 0; | ||
expectedThumbsUp = 0; | ||
break; | ||
case RatingType.Boo: | ||
expectedThumbsDown = 1; | ||
expectedThumbsUp = 0; | ||
break; | ||
case RatingType.Yay: | ||
expectedThumbsDown = 0; | ||
expectedThumbsUp = 1; | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(comment.YourThumb, Is.EqualTo(ratingType.ToDPad())); | ||
Assert.That(comment.ThumbsUp, Is.EqualTo(expectedThumbsUp)); | ||
Assert.That(comment.ThumbsDown, Is.EqualTo(expectedThumbsDown)); | ||
}); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters