slack-strava
slack-strava copied to clipboard
leaderboard query not working with number of days
Leaderboard queries are mostly self-explanatory, but this one has an odd behaviour:
leaderboard elapsed time last 14 days
It seems to have selected a zero length duration 27hours ago:
Maybe this is an unsupported query?
Looks like the parsing in "leaderboard elapsed time last 14 days" does not work as you'd expect, because Chronic parses "last 14 days" as a single day, but "leaderboard elapsed time since 14 days ago" works and returns the correct range. I opened https://github.com/mojombo/chronic/issues/431.
Try "past 14 days" is a workaround?
Repro:
+ it 'elapsed time last 14 days' do
+ allow(client.web_client).to receive(:chat_postMessage)
+ start_date = Time.now - 14.days
+ end_date = Time.now
+ expect_any_instance_of(Team).to receive(:leaderboard).with(metric: 'elapsed time', start_date: start_date, end_date: end_date).and_call_original
+ message_hook.call(client, Hashie::Mash.new(user: 'user', channel: 'DM', text: "#{SlackRubyBot.config.user} leaderboard elapsed time last 14 days"))
+ end
+
+ it 'elapsed time last 14 days (demonstrates parsing issue)' do
+ allow(client.web_client).to receive(:chat_postMessage)
+ # This test demonstrates that "last 14 days" is incorrectly parsed as a single day
+ # rather than a 14-day range. The user should use "since 14 days ago" instead.
+ expect_any_instance_of(Team).to receive(:leaderboard).with(metric: 'elapsed time', start_date: anything, end_date: anything).and_call_original
+ message_hook.call(client, Hashie::Mash.new(user: 'user', channel: 'DM', text: "#{SlackRubyBot.config.user} leaderboard elapsed time last 14 days"))
+ end
+
+ it 'elapsed time since 14 days ago' do
+ Timecop.freeze do
+ allow(client.web_client).to receive(:chat_postMessage)
+ start_date = Time.now - 14.days
+ end_date = Time.now
+ expect_any_instance_of(Team).to receive(:leaderboard).with(metric: 'elapsed time', start_date: start_date, end_date: end_date).and_call_original
+ message_hook.call(client, Hashie::Mash.new(user: 'user', channel: 'DM', text: "#{SlackRubyBot.config.user} leaderboard elapsed time since 14 days ago"))
+ end
+ end
+