public async Task SkipsBotMessages() { var payload = new SlackEventAPIPayload { Event = new Event { Channel = "CGWGZ90KV", // private channel #bottestsmore Bot_Id = "123", Text = "OLD! https://www.aftenposten.no/norge/i/L08awV/Haper-pa-mer-enn-ti-tusen-barn-og-unge-i-norske-klimastreiker?utm_source=my-unit-test" } }; var body = JsonConvert.SerializeObject(payload, JsonSettings.SlackSettings); var request = new APIGatewayProxyRequest { Body = body }; var validateOldness = new OldnessValidator(); var response = await validateOldness.Validate(request, new TestLambdaContext()); Assert.Equal(200, response.StatusCode); Assert.Equal("BOT", response.Body); }
private static async Task TestIt(string expected, string slackMessage) { var payload = new SlackEventAPIPayload { Event = new Event { Channel = "CGWGZ90KV", // private channel #bottestsmore Text = slackMessage, Ts = "1552671375.000200" } }; var body = JsonConvert.SerializeObject(payload, JsonSettings.SlackSettings); var request = new APIGatewayProxyRequest { Body = body }; var validateOldness = new OldnessValidator(); var response = await validateOldness.Validate(request, new TestLambdaContext()); Assert.Equal(200, response.StatusCode); Assert.Equal(expected, response.Body); }
public async Task Reacts() { var newMessage = new Event { Channel = "CGY1XJRM1", // public channel #tests Text = "SomeMessage containing an URL https://twitter.com/AukeHoekstra/status/1104095189117911040?s=09", Ts = "1553108688.002800" // https://smarteboka.slack.com/messages/CGY1XJRM1/convo/CGY1XJRM1-1553108688.002800/ }; var payload = new SlackEventAPIPayload { Event = newMessage }; var body = JsonConvert.SerializeObject(payload, JsonSettings.SlackSettings); var request = new APIGatewayProxyRequest { Body = body }; var appToken = Environment.GetEnvironmentVariable("OldBot_SlackApiKey_SlackApp"); var botToken = Environment.GetEnvironmentVariable("OldBot_SlackApiKey_BotUser"); var mockClient = new SlackTaskClientExtensions(appToken, botToken); var validateOldness = new OldnessValidator(mockClient); var response = await validateOldness.Validate(request, new TestLambdaContext()); Assert.Equal(200, response.StatusCode); Assert.Equal("ALREADY-OLDED", response.Body); }
public async Task DoesNotOldIfSearchReturnsEventMessage() { var newMessage = new Event { Channel = "CGWGZ90KV", // private channel #bottestsmore Text = "SomeMessage containing an URL http://db.no", Ts = "1552671375.000200" }; var payload = new SlackEventAPIPayload { Event = newMessage }; var body = JsonConvert.SerializeObject(payload, JsonSettings.SlackSettings); var request = new APIGatewayProxyRequest { Body = body }; var mockClient = new MockClient(); mockClient.SetSearchResponse(newMessage); var validateOldness = new OldnessValidator(mockClient); var response = await validateOldness.Validate(request, new TestLambdaContext()); Assert.Equal(200, response.StatusCode); Assert.Equal("NEW", response.Body); }
public async Task DoesNotOldIfIsSameAuthor() { var mockClient = new MockClient(); var existingMessage = new Event { Text = "A historic tale. I told you about http://db.no some time ago", User = "******", Ts = "1550000000.000000" // }; mockClient.SetSearchResponse(existingMessage); var newMessage = new SlackEventAPIPayload { Event = new Event { Text = "Woot, me, U0F3P72QM, is repeating the url http://db.no some time later", User = "******", Ts = "1660000000.000000" } }; var body = JsonConvert.SerializeObject(newMessage, JsonSettings.SlackSettings); var request = new APIGatewayProxyRequest { Body = body }; var validateOldness = new OldnessValidator(mockClient); var response = await validateOldness.Validate(request, new TestLambdaContext()); Assert.Equal(200, response.StatusCode); Assert.Equal("OLD-BUT-SAME-USER-SO-IGNORING", response.Body); }