feat(subscription): implement effective plan logic and update free plan features
This commit is contained in:
@@ -43,6 +43,24 @@ describe('useSubscription', () => {
|
||||
expect(result.current.isExpiringSoon).toBe(true);
|
||||
});
|
||||
|
||||
it('نبود اشتراک: امکانات را از effective_plan (پلن free) میگیرد', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'doctor' });
|
||||
get.mockResolvedValue({
|
||||
data: {
|
||||
subscription: null,
|
||||
effective_plan: { features: { patient_records: true, services: true, sms_panel: true }, max_secretaries: 1 },
|
||||
},
|
||||
});
|
||||
|
||||
const { result } = renderHookWithClient(() => useSubscription());
|
||||
await waitFor(() => expect(result.current.hasFeature('patient_records')).toBe(true));
|
||||
|
||||
expect(result.current.hasFeature('services')).toBe(true);
|
||||
expect(result.current.hasFeature('sms_panel')).toBe(true);
|
||||
expect(result.current.hasPlan).toBe(false);
|
||||
expect(result.current.maxSecretaries).toBe(1);
|
||||
});
|
||||
|
||||
it('برای نقش admin غیرفعال است (query اجرا نمیشود)', async () => {
|
||||
useAuthStore.setState({ primaryRole: 'admin' });
|
||||
const { result } = renderHookWithClient(() => useSubscription());
|
||||
|
||||
@@ -16,13 +16,14 @@ export function useSubscription() {
|
||||
});
|
||||
|
||||
const sub = data?.data?.subscription ?? null;
|
||||
const features: Record<string, boolean> = sub?.plan?.features ?? {};
|
||||
const maxSecretaries: number = sub?.plan?.max_secretaries ?? 1;
|
||||
const effectivePlan = data?.data?.effective_plan ?? sub?.plan ?? null;
|
||||
const features: Record<string, boolean> = effectivePlan?.features ?? {};
|
||||
const maxSecretaries: number = effectivePlan?.max_secretaries ?? 1;
|
||||
const hasPlan = sub !== null;
|
||||
|
||||
return {
|
||||
subscription: sub,
|
||||
hasFeature: (key: string) => hasPlan && (features[key] ?? false),
|
||||
hasFeature: (key: string) => features[key] ?? false,
|
||||
maxSecretaries,
|
||||
hasPlan,
|
||||
isExpiringSoon: (sub?.days_remaining ?? 0) > 0 && (sub?.days_remaining ?? 0) <= 7,
|
||||
|
||||
Reference in New Issue
Block a user