mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Merge pull request #37019 from BerriAI/litellm_mock_assertion_strength
test(ui): assert what collaborators are called with, not merely that they were
This commit is contained in:
commit
6a0bd0dffb
3 changed files with 27 additions and 13 deletions
|
|
@ -84,7 +84,9 @@ describe("useDiscountConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(false);
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalled();
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalledWith(
|
||||
"Please select a provider and enter discount percentage",
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false and notify when no discount is provided", async () => {
|
||||
|
|
@ -96,7 +98,9 @@ describe("useDiscountConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(false);
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalled();
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalledWith(
|
||||
"Please select a provider and enter discount percentage",
|
||||
);
|
||||
});
|
||||
|
||||
it("should return false and notify when the discount exceeds 100", async () => {
|
||||
|
|
@ -152,7 +156,7 @@ describe("useDiscountConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(true);
|
||||
expect(NotificationsManager.success).toHaveBeenCalled();
|
||||
expect(NotificationsManager.success).toHaveBeenCalledWith("Discount configuration updated successfully");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ describe("useMarginConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(false);
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalled();
|
||||
expect(NotificationsManager.fromBackend).toHaveBeenCalledWith("Please select a provider");
|
||||
});
|
||||
|
||||
it("should return false and notify when percentage is out of range", async () => {
|
||||
|
|
@ -160,7 +160,7 @@ describe("useMarginConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(true);
|
||||
expect(NotificationsManager.success).toHaveBeenCalled();
|
||||
expect(NotificationsManager.success).toHaveBeenCalledWith("Margin configuration updated successfully");
|
||||
});
|
||||
|
||||
it("should save a fixed amount margin and return true for a valid new provider", async () => {
|
||||
|
|
@ -189,7 +189,7 @@ describe("useMarginConfig", () => {
|
|||
});
|
||||
|
||||
expect(success!).toBe(true);
|
||||
expect(NotificationsManager.success).toHaveBeenCalled();
|
||||
expect(NotificationsManager.success).toHaveBeenCalledWith("Margin configuration updated successfully");
|
||||
});
|
||||
|
||||
it("should accept the global provider without provider_map lookup", async () => {
|
||||
|
|
|
|||
|
|
@ -1964,11 +1964,18 @@ describe("EntityUsageExport utils", () => {
|
|||
|
||||
handleExportCSV(mockSpendData, "daily", "Team", "team", mockTeamAliasMap);
|
||||
|
||||
expect(Papa.unparse).toHaveBeenCalled();
|
||||
expect(createObjectURLSpy).toHaveBeenCalled();
|
||||
const unparsedRows = vi.mocked(Papa.unparse).mock.calls[0][0] as Record<string, unknown>[];
|
||||
expect(unparsedRows).toHaveLength(3);
|
||||
const day1Team1 = unparsedRows.find((r) => r["Date"] === "2025-01-01" && r["Team ID"] === "team-1");
|
||||
expect(day1Team1?.["Cache Read Input Tokens"]).toBe(50);
|
||||
|
||||
const exportedBlob = createObjectURLSpy.mock.calls[0][0] as Blob;
|
||||
expect(exportedBlob.type).toBe("text/csv;charset=utf-8;");
|
||||
|
||||
expect(createElementSpy).toHaveBeenCalledWith("a");
|
||||
expect(appendChildSpy).toHaveBeenCalled();
|
||||
expect(removeChildSpy).toHaveBeenCalled();
|
||||
const attached = appendChildSpy.mock.calls[0][0] as HTMLAnchorElement;
|
||||
expect(attached.download).toMatch(/^team_usage_daily_.*\.csv$/);
|
||||
expect(removeChildSpy).toHaveBeenCalledWith(attached);
|
||||
});
|
||||
|
||||
it("should generate correct filename", () => {
|
||||
|
|
@ -2028,10 +2035,13 @@ describe("EntityUsageExport utils", () => {
|
|||
|
||||
handleExportJSON(mockSpendData, "daily", "Team", "team", mockDateRange, [], mockTeamAliasMap);
|
||||
|
||||
expect(createObjectURLSpy).toHaveBeenCalled();
|
||||
const exportedBlob = createObjectURLSpy.mock.calls[0][0] as Blob;
|
||||
expect(exportedBlob.type).toBe("application/json");
|
||||
|
||||
expect(createElementSpy).toHaveBeenCalledWith("a");
|
||||
expect(appendChildSpy).toHaveBeenCalled();
|
||||
expect(removeChildSpy).toHaveBeenCalled();
|
||||
const attached = appendChildSpy.mock.calls[0][0] as HTMLAnchorElement;
|
||||
expect(attached.download).toMatch(/^team_usage_daily_.*\.json$/);
|
||||
expect(removeChildSpy).toHaveBeenCalledWith(attached);
|
||||
});
|
||||
|
||||
it("should generate correct filename", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue