Fix start_date and end_date never being set in calculated totals - #1092
Open
arpitjain099 wants to merge 1 commit into
Open
Fix start_date and end_date never being set in calculated totals#1092arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The guard tested result.data[0].data, but result rows carry a date key, not a data key, so the branch never ran and start_date/end_date were never emitted. Inside the branch, result.date[0].date is a typo for result.data[0].date, so the branch would throw a TypeError if it ever did run. Both were introduced together in 55a6f79 when this logic moved out of process-ga-data.js. The pre-move code read result.data[0].date in both places, so this restores the original behavior. Also updates the totals expectation in the query_google_analytics test, which now sees the dates it should always have had. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are two bugs in the start/end date block in
src/process_results/result_totals_calculator.js, and they hide each other, so they have to be fixed together.The guard is
if (result.data[0].data). Result rows don't have adatakey, they havedateplus the metric keys, so the guard is always false andstart_date/end_dateare never set. Right inside that branch,result.date[0].dateshould beresult.data[0].date.result.dateis undefined, so if the guard ever passed, this would throw.That's why fixing only the guard is worse than leaving it alone: it turns a silent no-op into a TypeError. I checked this rather than assuming it. Correcting the guard on its own takes the suite from 1 pre-existing failure to 19, all
TypeError: Cannot read properties of undefined (reading '0').On intent, I didn't want to guess, so I traced it. Both typos came in together in 55a6f79, when this moved out of
process-ga-data.js. The code before that move was:So
result.data[0].datein both spots is the original behavior, and theresult.data.length > 0part is already covered by the early return at the top ofcalculateTotals. This restores that and nothing more.One knock-on:
test/actions/query_google_analytics.test.jsasserted a totals object with no dates in it. That fixture is 24 hourly rows all on 20170130, so it now getsstart_dateandend_dateof2017-01-30. I updated the expectation. Happy to hear if any consumer would rather not see these fields appear, since they've effectively been absent for years.Tests added in
test/process_results/result_totals_calculator.test.js: dates set from first and last row, a(other)first row skipped in favor of row 1, and rows with no date dimension still not getting the fields.Verified on Node 22 (per
.nvmrc) withNODE_ENV=test npx mocha:The one constant failure is
PostgresPublisher, which isECONNREFUSEDagainst a database I don't have locally. It fails identically on an unmodified checkout.npx eslint .andprettier --checkare both clean.