public void PostsUpdateWhenTrackedZendeskTicketChanges() { var zendeskApi = new Mock <IZendeskTicketApi>(); var ticket1 = new ZendeskTicket("12345", "description", "open", new ZendeskTicket.Comment[3]); var ticket2 = new ZendeskTicket("12345", "description", "open", new ZendeskTicket.Comment[5]); var persistence = new InMemoryKeyValueStore(); zendeskApi.Setup(x => x.FromId("12345")).ReturnsAsync(ticket1); var commandParser = CommandParser.For("track ZD#12345"); var zendeskTracker = new ZendeskTicketTracker(commandParser, persistence, zendeskApi.Object); zendeskTracker.ProcessMessage(new Message("a-channel", "a-user", "scbot track ZD#12345")); CollectionAssert.IsEmpty(zendeskTracker.ProcessTimerTick().Responses); zendeskApi.Setup(x => x.FromId("12345")).ReturnsAsync(ticket2); var ping = zendeskTracker.ProcessTimerTick().Responses.Single(); Assert.AreEqual("a-channel", ping.Channel); Assert.AreEqual("<https://redgatesupport.zendesk.com/agent/tickets/12345|ZD#12345> (description) updated: 2 comments added", ping.Message); // subsequent ticks should use updated values CollectionAssert.IsEmpty(zendeskTracker.ProcessTimerTick().Responses); }
public void CanTrackTicketFromUrl() { var zendeskApi = new Mock <IZendeskTicketApi>(MockBehavior.Strict); var ticket1 = new ZendeskTicket("12345", "description", "open", new ZendeskTicket.Comment[3]); var ticket2 = new ZendeskTicket("12345", "description", "open", new ZendeskTicket.Comment[5]); var persistence = new InMemoryKeyValueStore(); zendeskApi.Setup(x => x.FromId("12345")).ReturnsAsync(ticket1); var commandParser = CommandParser.For("track <https://redgatesupport.zendesk.com/agent/tickets/12345>"); var zendeskTracker = new ZendeskTicketTracker(commandParser, persistence, zendeskApi.Object); var result = zendeskTracker.ProcessMessage(new Message("a-channel", "a-user", @"scbot track <https://redgatesupport.zendesk.com/agent/tickets/12345>")); Assert.AreEqual("Now tracking ZD#12345. To stop tracking, use `untrack ZD#12345`", result.Responses.Single().Message); }
public void CanUntrackTickets() { var initialJson = @"[{""Value"":{""Id"":""12345"",""Description"":""the description"",""Status"":""hold"",""CommentCount"":5},""Channel"":""a-channel""}]"; var persistence = new Mock <IKeyValueStore>(); persistence.Setup(x => x.Get("tracked-zd-tickets")).Returns(initialJson); var commandParser = CommandParser.For("untrack ZD#12345"); var zendeskTracker = new ZendeskTicketTracker(commandParser, persistence.Object, null); var response = zendeskTracker.ProcessMessage(new Message("a-channel", "a-user", "scbot untrack ZD#12345")).Responses.Single(); Assert.AreEqual("No longer tracking ZD#12345.", response.Message); persistence.VerifyAll(); persistence.Verify(x => x.Set("tracked-zd-tickets", "[]")); }