mirror of https://github.com/ppy/osu
Add test for `ChannelManager.MarkChannelAsRead`
This commit is contained in:
parent
7d6f7ac75e
commit
2f9f1ba862
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
|
@ -19,6 +20,7 @@ public class TestSceneChannelManager : OsuTestScene
|
|||
{
|
||||
private ChannelManager channelManager;
|
||||
private int currentMessageId;
|
||||
List<Message> sentMessages;
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
|
@ -34,6 +36,7 @@ public void SetUpSteps()
|
|||
AddStep("register request handling", () =>
|
||||
{
|
||||
currentMessageId = 0;
|
||||
sentMessages = new List<Message>();
|
||||
|
||||
((DummyAPIAccess)API).HandleRequest = req =>
|
||||
{
|
||||
|
@ -44,7 +47,7 @@ public void SetUpSteps()
|
|||
return true;
|
||||
|
||||
case PostMessageRequest postMessage:
|
||||
postMessage.TriggerSuccess(new Message(++currentMessageId)
|
||||
var message = new Message(++currentMessageId)
|
||||
{
|
||||
IsAction = postMessage.Message.IsAction,
|
||||
ChannelId = postMessage.Message.ChannelId,
|
||||
|
@ -52,7 +55,10 @@ public void SetUpSteps()
|
|||
Links = postMessage.Message.Links,
|
||||
Timestamp = postMessage.Message.Timestamp,
|
||||
Sender = postMessage.Message.Sender
|
||||
});
|
||||
};
|
||||
|
||||
sentMessages.Add(message);
|
||||
postMessage.TriggerSuccess(message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -83,12 +89,59 @@ public void TestCommandsPostedToCorrectChannelWhenNotCurrent()
|
|||
AddAssert("/np command received by channel 2", () => channel2.Messages.Last().Content.Contains("is listening to"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMarkAsReadIgnoringLocalMessages() {
|
||||
Channel channel = null;
|
||||
|
||||
AddStep("join channel and select it", () =>
|
||||
{
|
||||
channelManager.JoinChannel(channel = createChannel(1, ChannelType.Public));
|
||||
|
||||
channelManager.CurrentChannel.Value = channel;
|
||||
});
|
||||
|
||||
AddStep("post message", () => channelManager.PostMessage("Something interesting"));
|
||||
AddUntilStep("wait until the message is posted", () => channel.Messages.Count == sentMessages.Count);
|
||||
|
||||
AddStep("post /help command", () => channelManager.PostCommand("help", channel));
|
||||
AddStep("post /me command with no action", () => channelManager.PostCommand("me", channel));
|
||||
AddStep("post /join command with no channel", () => channelManager.PostCommand("join", channel));
|
||||
AddStep("post /join command with non-existent channel", () => channelManager.PostCommand("join i-dont-exist", channel));
|
||||
AddStep("post non-existent command", () => channelManager.PostCommand("non-existent-cmd arg", channel));
|
||||
|
||||
AddStep("register mark channel as read request handler", () => {
|
||||
((DummyAPIAccess)API).HandleRequest = req =>
|
||||
{
|
||||
switch (req)
|
||||
{
|
||||
case MarkChannelAsReadRequest markRead:
|
||||
var isSentMessage = sentMessages.Contains(markRead.Message);
|
||||
|
||||
AddAssert("mark channel as read called with a real message", () => isSentMessage);
|
||||
|
||||
if(isSentMessage) {
|
||||
markRead.TriggerSuccess();
|
||||
} else {
|
||||
markRead.TriggerFailure(new APIException("unknown message!", null));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
AddStep("mark channel as read", () => channelManager.MarkChannelAsRead(channel));
|
||||
}
|
||||
|
||||
private Channel createChannel(int id, ChannelType type) => new Channel(new User())
|
||||
{
|
||||
Id = id,
|
||||
Name = $"Channel {id}",
|
||||
Topic = $"Topic of channel {id} with type {type}",
|
||||
Type = type,
|
||||
LastMessageId = 0,
|
||||
};
|
||||
|
||||
private class ChannelManagerContainer : CompositeDrawable
|
||||
|
|
|
@ -9,16 +9,16 @@ namespace osu.Game.Online.API.Requests
|
|||
{
|
||||
public class MarkChannelAsReadRequest : APIRequest
|
||||
{
|
||||
private readonly Channel channel;
|
||||
private readonly Message message;
|
||||
public readonly Channel Channel;
|
||||
public readonly Message Message;
|
||||
|
||||
public MarkChannelAsReadRequest(Channel channel, Message message)
|
||||
{
|
||||
this.channel = channel;
|
||||
this.message = message;
|
||||
this.Channel = channel;
|
||||
this.Message = message;
|
||||
}
|
||||
|
||||
protected override string Target => $"chat/channels/{channel.Id}/mark-as-read/{message.Id}";
|
||||
protected override string Target => $"chat/channels/{Channel.Id}/mark-as-read/{Message.Id}";
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue