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 DoesNotUpdateIfZendeskApiReturnsNull() { var zendeskApi = new Mock <IZendeskTicketApi>(); zendeskApi.Setup(x => x.FromId(It.IsAny <string>())).ReturnsAsync(default(ZendeskTicket)); 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 slackCommandParser = new Mock <ICommandParser>(); var zendeskTracker = new ZendeskTicketTracker(slackCommandParser.Object, persistence.Object, zendeskApi.Object); zendeskTracker.ProcessTimerTick(); persistence.Verify(x => x.Set(It.IsAny <string>(), It.IsAny <string>()), Times.Never()); }