Merge remote-tracking branch 'remotes/from/ce/release/2.x.x' into release/2.x.x

This commit is contained in:
hc-github-team-secure-vault-core 2026-05-06 23:15:21 +00:00
commit 9d91b417f0
2 changed files with 42 additions and 1 deletions

View File

@ -8,6 +8,8 @@ import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { normalizeMetricData, NormalizedBillingMetrics } from 'vault/utils/metrics-helpers';
import { subMonths } from 'date-fns';
import { formatInTimeZone } from 'date-fns-tz';
import type ApiService from 'vault/services/api';
import type { Month, NormalizedMetricsData } from 'vault/vault/billing/overview';
@ -87,8 +89,13 @@ export default class BillingPageOverview extends Component {
}
fetchBillingMetrics = async () => {
const today = new Date();
const currentMonth = formatInTimeZone(today, 'UTC', 'yyyy-MM');
const previousMonth = formatInTimeZone(subMonths(today, 1), 'UTC', 'yyyy-MM');
const response: SystemReadBillingOverviewResponse | null | undefined =
await this.api.sys.systemReadBillingOverview();
await this.api.sys.systemReadBillingOverview(currentMonth, undefined, previousMonth);
this.months = (response?.months?.slice(0, 2) as Month[]) || [];
const updatedMonthFromSelectedMonth = this.months.find(
(month: Month) => month.month === this.selectedDateOption?.month

View File

@ -5,6 +5,7 @@
import { test, expect } from '@playwright/test';
import { METRICS_DATA_RESPONSE } from '../../../tests/helpers/billing/stubs';
import { formatInTimeZone } from 'date-fns-tz';
test('billing metrics dashboard workflow', async ({ page }) => {
await test.step('navigate to billing metrics page and mock data', async () => {
@ -66,3 +67,36 @@ test('billing metrics dashboard workflow', async ({ page }) => {
);
});
});
test('billing metrics dashboard api returns two months of data', async ({ page }) => {
await page.route('**/sys/license/features', async (route) =>
route.fulfill({ json: { features: ['Consumption Billing'] } })
);
await page.goto('dashboard');
// Set up response listener before clicking the link
const responsePromise = page.waitForResponse('**/sys/billing/overview**');
await page.getByRole('link', { name: 'Billing metrics' }).click();
// Wait for the API response and get the actual months returned
const response = await responsePromise;
const data = await response.json();
const months = data.data?.months || [];
// Verify we have at least 2 months of data
expect(months.length).toEqual(2);
// Verify both months appear in the dropdown options
const currentMonth = new Date(months[0].month);
const previousMonth = new Date(months[1].month);
// Click the date range dropdown to verify both months are available
await page.getByRole('button', { name: formatInTimeZone(currentMonth, 'UTC', 'MMMM') }).click();
await expect(page.getByRole('option', { name: formatInTimeZone(currentMonth, 'UTC', 'MMMM') })).toHaveText(
formatInTimeZone(currentMonth, 'UTC', 'MMMM yyyy')
);
await expect(page.getByRole('option', { name: formatInTimeZone(previousMonth, 'UTC', 'MMMM') })).toHaveText(
formatInTimeZone(previousMonth, 'UTC', 'MMMM yyyy')
);
});