Skip to content

Scheduling infrastructure for absolutely everyone.

feat: add test to verify unpublished platform orgs are excluded from credit usage (#22567)

Anik Dhabal Babubb4260c98be8
diff --git a/packages/features/ee/billing/credit-service.test.ts b/packages/features/ee/billing/credit-service.test.ts
index 18560489163..927a7dfb2f2 100644
--- a/packages/features/ee/billing/credit-service.test.ts
+++ b/packages/features/ee/billing/credit-service.test.ts
@@ -644,5 +644,33 @@ describe("CreditService", () => {
});
});
});
+
+ it("should skip unpublished platform organizations and return regular team with credits", async () => {
+ vi.mocked(MembershipRepository.findAllAcceptedPublishedTeamMemberships).mockResolvedValue([
+ { teamId: 2 },
+ ]);
+
+ vi.mocked(CreditsRepository.findCreditBalance).mockResolvedValue({
+ id: "2",
+ additionalCredits: 100,
+ limitReachedAt: null,
+ warningSentAt: null,
+ });
+ vi.spyOn(CreditService.prototype, "_getAllCreditsForTeam").mockResolvedValue({
+ totalMonthlyCredits: 500,
+ totalRemainingMonthlyCredits: 200,
+ additionalCredits: 100,
+ });
+ const result = await creditService.getTeamWithAvailableCredits(1);
+ expect(result).toEqual({
+ teamId: 2,
+ availableCredits: 300,
+ creditType: CreditType.MONTHLY,
+ });
+
+ expect(MembershipRepository.findAllAcceptedPublishedTeamMemberships).toHaveBeenCalledWith(1, MOCK_TX);
+ expect(CreditsRepository.findCreditBalance).toHaveBeenCalledTimes(1);
+ expect(CreditsRepository.findCreditBalance).toHaveBeenCalledWith({ teamId: 2 }, MOCK_TX);
+ });
});
});