Skip to content

Commit

Permalink
test(backend): fix test too long and time zone issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Nov 1, 2024
1 parent 299cf49 commit 491c132
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions backend/services/congestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe("CongestionSvc", () => {
groupby: "hour",
agg: "max",
begin: "2024-10-29T20:00:00+08:00",
end: "2024-10-30T20:00:00+08:00",
end: "2024-10-29T23:00:00+08:00",
});
expect(grouped.length).toEqual(24);
expect(grouped.length).toEqual(3);
expect(grouped.every((c) => typeof c.rating.value === "number")).toBe(true);
// check first group is aggregated correctly
const firstHour = await congestion.getCongestions({
Expand Down
6 changes: 4 additions & 2 deletions backend/services/congestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class CongestionSvc {
// performance: only query last updated_on if 'begin' or 'end' timestamp is omitted.
const lastUpdated = await this.lastUpdatedOn();
beginDate = await this.lastUpdatedOn();
endDate = addDate<TZDate, TZDate>(lastUpdated, { days: 1 });
endDate = new TZDate(addDate(lastUpdated, { days: 1 })).withTimeZone(
"Asia/Singapore",
);
}

// filter by camera_id if specified
Expand Down Expand Up @@ -160,7 +162,7 @@ export class CongestionSvc {
// first congestion of each rating value sorted group is min.
grouped.push(await getFirst());
} else {
// first congestion of each rating value sorted in descending order group is max
// agg is max: first congestion of each rating value sorted in descending order group is max
grouped.push(
(
await group.orderBy("rating.value", "desc").limit(1).get()
Expand Down

0 comments on commit 491c132

Please sign in to comment.