2022-06-14 11:51:11 +02:00
|
|
|
import {
|
2022-06-21 11:22:27 +02:00
|
|
|
trialHasExpired,
|
|
|
|
canExtendTrial,
|
|
|
|
trialExpiresSoon,
|
2022-06-14 11:51:11 +02:00
|
|
|
} from 'utils/instanceTrial';
|
|
|
|
import { InstancePlan, InstanceState } from 'interfaces/instance';
|
2022-06-21 11:22:27 +02:00
|
|
|
import { subHours, addHours, addDays } from 'date-fns';
|
2022-06-14 11:51:11 +02:00
|
|
|
|
2022-06-21 11:22:27 +02:00
|
|
|
test('trialHasExpired', () => {
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
trialHasExpired({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
2022-06-21 11:22:27 +02:00
|
|
|
state: InstanceState.UNASSIGNED,
|
2022-06-14 11:51:11 +02:00
|
|
|
})
|
2022-06-21 11:22:27 +02:00
|
|
|
).toEqual(false);
|
|
|
|
expect(
|
|
|
|
trialHasExpired({
|
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.ACTIVE,
|
|
|
|
})
|
|
|
|
).toEqual(false);
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
trialHasExpired({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.TRIAL,
|
|
|
|
trialExpiry: addHours(new Date(), 2).toISOString(),
|
|
|
|
})
|
|
|
|
).toEqual(false);
|
2022-06-21 11:22:27 +02:00
|
|
|
expect(
|
|
|
|
trialHasExpired({
|
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.TRIAL,
|
|
|
|
trialExpiry: subHours(new Date(), 2).toISOString(),
|
|
|
|
})
|
|
|
|
).toEqual(true);
|
|
|
|
expect(
|
|
|
|
trialHasExpired({
|
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.EXPIRED,
|
|
|
|
})
|
|
|
|
).toEqual(true);
|
|
|
|
expect(
|
|
|
|
trialHasExpired({
|
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.CHURNED,
|
|
|
|
})
|
|
|
|
).toEqual(true);
|
2022-06-14 11:51:11 +02:00
|
|
|
});
|
|
|
|
|
2022-06-21 11:22:27 +02:00
|
|
|
test('trialExpiresSoon', () => {
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
trialExpiresSoon({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.TRIAL,
|
2022-06-21 11:22:27 +02:00
|
|
|
trialExpiry: addDays(new Date(), 12).toISOString(),
|
2022-06-14 11:51:11 +02:00
|
|
|
})
|
2022-06-21 11:22:27 +02:00
|
|
|
).toEqual(false);
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
trialExpiresSoon({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
|
|
|
state: InstanceState.TRIAL,
|
2022-06-21 11:22:27 +02:00
|
|
|
trialExpiry: addDays(new Date(), 8).toISOString(),
|
2022-06-14 11:51:11 +02:00
|
|
|
})
|
2022-06-21 11:22:27 +02:00
|
|
|
).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('canExtendTrial', () => {
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
canExtendTrial({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
2022-06-21 11:22:27 +02:00
|
|
|
state: InstanceState.EXPIRED,
|
2022-06-14 11:51:11 +02:00
|
|
|
})
|
2022-06-21 11:22:27 +02:00
|
|
|
).toEqual(true);
|
2022-06-14 11:51:11 +02:00
|
|
|
expect(
|
2022-06-21 11:22:27 +02:00
|
|
|
canExtendTrial({
|
2022-06-14 11:51:11 +02:00
|
|
|
plan: InstancePlan.UNKNOWN,
|
2022-06-21 11:22:27 +02:00
|
|
|
state: InstanceState.EXPIRED,
|
|
|
|
trialExtended: 1,
|
2022-06-14 11:51:11 +02:00
|
|
|
})
|
2022-06-21 11:22:27 +02:00
|
|
|
).toEqual(false);
|
2022-06-14 11:51:11 +02:00
|
|
|
});
|