This commit is contained in:
Alex Zhang 2026-09-29 10:48:09 -07:00 • committed by GitHub
commit 388fdb9ff4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 10 deletions

View file

@ -915,7 +915,7 @@ describe("UsagePage", () => {
expect(screen.getByText("UniqueUser (user-unique)")).toBeInTheDocument();
});
it("should pass selected userId to aggregated call", async () => {
it("should include the current UTC day in global usage", async () => {
renderWithProviders(<UsagePage {...defaultProps} />);
await waitFor(() => {
@ -928,6 +928,7 @@ describe("UsagePage", () => {
expect.any(Date),
expect.any(Date),
null,
true,
);
});
});
@ -1020,6 +1021,7 @@ describe("UsagePage", () => {
expect.any(Date),
expect.any(Date),
"user-123",
true,
);
});
});
@ -1133,10 +1135,24 @@ describe("UsagePage", () => {
});
// Verify first page call
expect(mockUserDailyActivityCall).toHaveBeenCalledWith("test-token", expect.any(Date), expect.any(Date), 1, null);
expect(mockUserDailyActivityCall).toHaveBeenCalledWith(
"test-token",
expect.any(Date),
expect.any(Date),
1,
null,
true,
);
// Verify second page call
expect(mockUserDailyActivityCall).toHaveBeenCalledWith("test-token", expect.any(Date), expect.any(Date), 2, null);
expect(mockUserDailyActivityCall).toHaveBeenCalledWith(
"test-token",
expect.any(Date),
expect.any(Date),
2,
null,
true,
);
});
});

View file

@ -192,7 +192,7 @@ const UsagePage: React.FC<UsagePageProps> = ({ teams, organizations }) => {
const rangeKey = currentAggregatedRangeKey;
setAggregatedLoading(true);
userDailyActivityAggregatedCall(accessToken, startTime, endTime, effectiveUserId)
userDailyActivityAggregatedCall(accessToken, startTime, endTime, effectiveUserId, true)
.then((data) => {
if (aggregatedFetchIdRef.current !== fetchId) return;
setAggregatedData({ rangeKey, value: data });
@ -237,7 +237,7 @@ const UsagePage: React.FC<UsagePageProps> = ({ teams, organizations }) => {
// Paginated fallback — only enabled when aggregated endpoint fails
const paginatedResult = usePaginatedDailyActivity({
fetchFn: userDailyActivityCall,
args: [accessToken, startTime, endTime, effectiveUserId],
args: [accessToken, startTime, endTime, effectiveUserId, true],
enabled: aggregatedFailed && !!accessToken && !!startTime && !!endTime,
});

View file

@ -776,11 +776,12 @@ describe("daily activity api_key filter", () => {
const originalFetch = global.fetch;
const captureFetch = () => {
const mockFetch = vi.fn<typeof fetch>().mockResolvedValue(
new Response(JSON.stringify({ results: [], metadata: {} }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
const mockFetch = vi.fn<typeof fetch>().mockImplementation(
async () =>
new Response(JSON.stringify({ results: [], metadata: {} }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
global.fetch = mockFetch;
return mockFetch;
@ -795,6 +796,24 @@ describe("daily activity api_key filter", () => {
global.fetch = originalFetch;
});
it.each([false, true])(
"serializes the current UTC day opt-in (%s) on both user activity routes",
async (includeCurrentUtcDay) => {
const mockFetch = captureFetch();
await Networking.userDailyActivityCall("sk-key", start, end, 1, "user-123", includeCurrentUtcDay);
await Networking.userDailyActivityAggregatedCall("sk-key", start, end, "user-123", includeCurrentUtcDay);
expect(mockFetch).toHaveBeenCalledTimes(2);
for (const [input] of mockFetch.mock.calls) {
const url = new URL(String(input), "http://localhost");
expect(url.searchParams.get("include_current_utc_day")).toBe(includeCurrentUtcDay ? "true" : null);
expect(url.searchParams.get("user_id")).toBe("user-123");
expect(url.searchParams.get("timezone")).toBe(String(new Date().getTimezoneOffset()));
}
},
);
it("sends the key hash as api_key from the paginated caller", async () => {
const mockFetch = captureFetch();