-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
512 Added max-recency boundries #526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bd9c67a
to
b2e39ac
Compare
3e764b7
to
1dfbc65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's create some tests for the timeRanges
. In order not o mess with db calls let's create another function that start after the db call.
Let me know if you want to talk about it.
54864ff
to
486645c
Compare
const organizations = latestInsight?.adAccount?.organizations ?? []; | ||
|
||
const organizationWithHighestTier = | ||
organizations.length > 0 | ||
? organizations.sort((a, b) => tierConstraints[b.tier].order - tierConstraints[a.tier].order)[0].tier | ||
: undefined; | ||
|
||
const maxRecency = tierConstraints[organizationWithHighestTier ?? Tier.Launch].maxRecency; | ||
|
||
if (initial) { | ||
const range = getLastXMonths(); | ||
|
||
if (!organizationWithHighestTier) { | ||
return splitTimeRange(tierConstraints[Tier.Launch].maxRecency, range.since, range.until); | ||
} | ||
|
||
return splitTimeRange(maxRecency, range.since, range.until); | ||
} | ||
const furthestDate = addInterval(new Date(), 'day', -maxRecency); | ||
const insightDateWithinLimit = latestInsight && latestInsight.date > furthestDate ? latestInsight.date : furthestDate; | ||
const range = getDayPriorTillTomorrow(insightDateWithinLimit); | ||
return splitTimeRange(maxRecency, range.since, range.until); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const organizations = latestInsight?.adAccount?.organizations ?? []; | |
const organizationWithHighestTier = | |
organizations.length > 0 | |
? organizations.sort((a, b) => tierConstraints[b.tier].order - tierConstraints[a.tier].order)[0].tier | |
: undefined; | |
const maxRecency = tierConstraints[organizationWithHighestTier ?? Tier.Launch].maxRecency; | |
if (initial) { | |
const range = getLastXMonths(); | |
if (!organizationWithHighestTier) { | |
return splitTimeRange(tierConstraints[Tier.Launch].maxRecency, range.since, range.until); | |
} | |
return splitTimeRange(maxRecency, range.since, range.until); | |
} | |
const furthestDate = addInterval(new Date(), 'day', -maxRecency); | |
const insightDateWithinLimit = latestInsight && latestInsight.date > furthestDate ? latestInsight.date : furthestDate; | |
const range = getDayPriorTillTomorrow(insightDateWithinLimit); | |
return splitTimeRange(maxRecency, range.since, range.until); | |
return testTimeRange(initial, latestInsight); |
I am a bit confused. You have created a testTimeRange
(probably a name that we need to change) function that you test, but the product code does not use it.
}; | ||
|
||
const ranges = testTimeRange(false, dummyInsight); | ||
assert.strictEqual(ranges.length, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that these tests will fail as time passes. This should help you.
@@ -57,4 +94,31 @@ void describe('splitTimeRange tests', () => { | |||
assert.strictEqual(ranges[2].since.toISOString(), '2021-06-30T00:00:00.000Z'); | |||
assert.strictEqual(ranges[2].until.toISOString(), '2021-09-25T00:00:00.000Z'); | |||
}); | |||
|
|||
void it('returns split time range when passed with false initial', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a test where the last insight was 3 months back and the tier is Launch?
fd09815
to
57df657
Compare
assert.strictEqual(ranges.length, 26); | ||
assert.strictEqual(ranges[0].since.toISOString(), '2024-01-01T00:00:00.000Z'); | ||
assert.strictEqual(ranges[0].until.toISOString(), '2024-01-07T00:00:00.000Z'); | ||
assert.strictEqual(ranges[1].since.toISOString(), '2024-01-08T00:00:00.000Z'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is find not to check all 26 ranges, but please check the first and the last at least.
assert.strictEqual(ranges[0].until.toISOString(), '2024-06-25T18:30:00.000Z'); | ||
}); | ||
|
||
void it('returns correct time range when last insight was 3 months ago and tier is Launch', (context) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these last two test should produce the same result. I would expect one range from midnight 18 till 26 midnight. This means that the existing code has a bug.
0fa1648
to
b6d4ab5
Compare
b6d4ab5
to
f13697c
Compare
Added the data limit for maximum recency allowed by each tier