## Description - Replaces Stripe Checkout session flow with direct card charging for AI credit top-ups - Adds a two-step confirmation modal (select package → confirm purchase) for better UX - Creates Stripe invoice directly and charges the customer's default payment method immediately ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Using the specs - UI manual test cases <img width="945" height="580" alt="image" src="https://github.com/user-attachments/assets/52bdad46-cd0e-4927-b13f-54c6b6353bcc" /> <img width="945" height="580" alt="image" src="https://github.com/user-attachments/assets/231bc7e9-41ac-440d-a93d-cba45a4d3e3e" /> ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
import accountAPI from '../account';
|
|
import ApiClient from '../../ApiClient';
|
|
|
|
describe('#enterpriseAccountAPI', () => {
|
|
it('creates correct instance', () => {
|
|
expect(accountAPI).toBeInstanceOf(ApiClient);
|
|
expect(accountAPI).toHaveProperty('get');
|
|
expect(accountAPI).toHaveProperty('show');
|
|
expect(accountAPI).toHaveProperty('create');
|
|
expect(accountAPI).toHaveProperty('update');
|
|
expect(accountAPI).toHaveProperty('delete');
|
|
expect(accountAPI).toHaveProperty('checkout');
|
|
expect(accountAPI).toHaveProperty('toggleDeletion');
|
|
expect(accountAPI).toHaveProperty('createTopupCheckout');
|
|
expect(accountAPI).toHaveProperty('getLimits');
|
|
});
|
|
|
|
describe('API calls', () => {
|
|
const originalAxios = window.axios;
|
|
const axiosMock = {
|
|
post: vi.fn(() => Promise.resolve()),
|
|
get: vi.fn(() => Promise.resolve()),
|
|
patch: vi.fn(() => Promise.resolve()),
|
|
delete: vi.fn(() => Promise.resolve()),
|
|
};
|
|
|
|
beforeEach(() => {
|
|
window.axios = axiosMock;
|
|
});
|
|
|
|
afterEach(() => {
|
|
window.axios = originalAxios;
|
|
});
|
|
|
|
it('#checkout', () => {
|
|
accountAPI.checkout();
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/checkout'
|
|
);
|
|
});
|
|
|
|
it('#subscription', () => {
|
|
accountAPI.subscription();
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/subscription'
|
|
);
|
|
});
|
|
|
|
it('#toggleDeletion with delete action', () => {
|
|
accountAPI.toggleDeletion('delete');
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/toggle_deletion',
|
|
{ action_type: 'delete' }
|
|
);
|
|
});
|
|
|
|
it('#toggleDeletion with undelete action', () => {
|
|
accountAPI.toggleDeletion('undelete');
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/toggle_deletion',
|
|
{ action_type: 'undelete' }
|
|
);
|
|
});
|
|
|
|
it('#createTopupCheckout with credits', () => {
|
|
accountAPI.createTopupCheckout(1000);
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/topup_checkout',
|
|
{ credits: 1000 }
|
|
);
|
|
});
|
|
|
|
it('#createTopupCheckout with different credit amounts', () => {
|
|
const creditAmounts = [1000, 2500, 6000, 12000];
|
|
creditAmounts.forEach(credits => {
|
|
accountAPI.createTopupCheckout(credits);
|
|
expect(axiosMock.post).toHaveBeenCalledWith(
|
|
'/enterprise/api/v1/topup_checkout',
|
|
{ credits }
|
|
);
|
|
});
|
|
});
|
|
|
|
it('#getLimits', () => {
|
|
accountAPI.getLimits();
|
|
expect(axiosMock.get).toHaveBeenCalledWith('/enterprise/api/v1/limits');
|
|
});
|
|
});
|
|
});
|