feat: add web testing foundation with infra-backed suites (#349)

* feat: add web test framework with infra-backed suites

* fix: honor DATABASE_URL env in integration prepare script

* fix: apply web test review feedback

* fix: streamline web test infra lifecycle and workflow scope
This commit is contained in:
KM Koushik
2026-02-16 09:13:29 +11:00
committed by GitHub
parent 09bdb8aaad
commit 487902421b
33 changed files with 1676 additions and 39 deletions
+2 -2
View File
@@ -54,9 +54,9 @@ export function getUsageDate(): string {
* @param transactionUsage Number of transaction emails sent
* @returns Total usage units rounded down to nearest integer
*/
export function getUsageUinits(
export function getUsageUnits(
marketingUsage: number,
transactionUsage: number
transactionUsage: number,
) {
return (
marketingUsage +
+35
View File
@@ -0,0 +1,35 @@
import { EmailUsageType } from "@prisma/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
getCost,
getUsageDate,
getUsageTimestamp,
getUsageUnits,
TRANSACTIONAL_UNIT_CONVERSION,
} from "~/lib/usage";
describe("usage helpers", () => {
afterEach(() => {
vi.useRealTimers();
});
it("returns yesterday date and timestamp", () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-02-08T12:00:00.000Z"));
expect(getUsageDate()).toBe("2026-02-07");
expect(getUsageTimestamp()).toBe(
Math.floor(new Date("2026-02-07T12:00:00.000Z").getTime() / 1000),
);
});
it("converts transactional usage into billing units", () => {
const units = getUsageUnits(100, 40);
expect(units).toBe(100 + Math.floor(40 / TRANSACTIONAL_UNIT_CONVERSION));
});
it("calculates cost per email type", () => {
expect(getCost(10, EmailUsageType.MARKETING)).toBe(0.01);
expect(getCost(4, EmailUsageType.TRANSACTIONAL)).toBe(0.001);
});
});