Gate AI editing features behind license (trial users no longer get AI editing)
This commit is contained in:
@ -16,7 +16,7 @@ function mockElectronAPI(overrides: Record<string, any> = {}) {
|
||||
describe('licenseStore', () => {
|
||||
beforeEach(() => {
|
||||
mockElectronAPI();
|
||||
useLicenseStore.setState({ status: null, isLoaded: false, canEdit: true, showDialog: false });
|
||||
useLicenseStore.setState({ status: null, isLoaded: false, canEdit: true, canUseAI: false, showDialog: false });
|
||||
});
|
||||
|
||||
describe('canEdit', () => {
|
||||
@ -45,10 +45,28 @@ describe('licenseStore', () => {
|
||||
});
|
||||
|
||||
test('is false when status is null', () => {
|
||||
useLicenseStore.setState({ status: null, canEdit: true });
|
||||
useLicenseStore.setState({ status: null, canEdit: true, canUseAI: false });
|
||||
useLicenseStore.getState().setStatus(null);
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
});
|
||||
|
||||
test('is true for Licensed status', () => {
|
||||
useLicenseStore.getState().setStatus({ tag: 'Licensed', license: { license_id: 'x', tier: 'pro', customer_email: 'a@b.com', expires_at: 9999999999, features: [], issued_at: 1, max_activations: 1 } });
|
||||
expect(useLicenseStore.getState().canEdit).toBe(true);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(true);
|
||||
});
|
||||
|
||||
test('is false for Trial status', () => {
|
||||
useLicenseStore.getState().setStatus({ tag: 'Trial', days_remaining: 5, started_at: Date.now() });
|
||||
expect(useLicenseStore.getState().canEdit).toBe(true);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
|
||||
test('is false for Expired status', () => {
|
||||
useLicenseStore.getState().setStatus({ tag: 'Expired' });
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkStatus', () => {
|
||||
@ -76,6 +94,7 @@ describe('licenseStore', () => {
|
||||
await useLicenseStore.getState().checkStatus();
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Expired');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
|
||||
test('handles missing electronAPI', async () => {
|
||||
@ -83,6 +102,7 @@ describe('licenseStore', () => {
|
||||
await useLicenseStore.getState().checkStatus();
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Expired');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
|
||||
test('sets isLoaded to true after check', async () => {
|
||||
@ -99,6 +119,7 @@ describe('licenseStore', () => {
|
||||
expect(result).toBe(true);
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Licensed');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(true);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(true);
|
||||
});
|
||||
|
||||
test('returns false on invalid key', async () => {
|
||||
@ -131,6 +152,7 @@ describe('licenseStore', () => {
|
||||
await useLicenseStore.getState().deactivateLicense();
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Expired');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
|
||||
test('restores Trial when trial is still valid', async () => {
|
||||
@ -141,14 +163,16 @@ describe('licenseStore', () => {
|
||||
await useLicenseStore.getState().deactivateLicense();
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Trial');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(true);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
|
||||
test('handles API error', async () => {
|
||||
mockElectronAPI({ deactivateLicense: vi.fn().mockRejectedValue(new Error('fail')) });
|
||||
useLicenseStore.setState({ status: { tag: 'Licensed', license: {} as any }, canEdit: true });
|
||||
useLicenseStore.setState({ status: { tag: 'Licensed', license: {} as any }, canEdit: true, canUseAI: true });
|
||||
await useLicenseStore.getState().deactivateLicense();
|
||||
expect(useLicenseStore.getState().status?.tag).toBe('Expired');
|
||||
expect(useLicenseStore.getState().canEdit).toBe(false);
|
||||
expect(useLicenseStore.getState().canUseAI).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user