|
| 1 | +import { add, sub } from 'date-fns' |
| 2 | +import { LeaseStatus } from '@onecore/types' |
| 3 | + |
| 4 | +import { mapToOnecoreLease } from '../../helpers/tenfast' |
| 5 | +import * as factory from '../factories' |
| 6 | + |
| 7 | +describe('calculateLeaseStatus (via mapToOnecoreLease)', () => { |
| 8 | + it('returns PendingSignature for signingInProgress stage', () => { |
| 9 | + const lease = factory.tenfastLease.build({ |
| 10 | + stage: 'signingInProgress', |
| 11 | + signed: false, |
| 12 | + startDate: sub(new Date(), { days: 1 }), |
| 13 | + endDate: null, |
| 14 | + }) |
| 15 | + |
| 16 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.PendingSignature) |
| 17 | + }) |
| 18 | + |
| 19 | + it('returns PreliminaryTerminated for requestedCancellation stage', () => { |
| 20 | + const lease = factory.tenfastLease.build({ |
| 21 | + stage: 'requestedCancellation', |
| 22 | + signed: true, |
| 23 | + startDate: sub(new Date(), { days: 30 }), |
| 24 | + endDate: add(new Date(), { days: 30 }), |
| 25 | + }) |
| 26 | + |
| 27 | + expect(mapToOnecoreLease(lease).status).toBe( |
| 28 | + LeaseStatus.PreliminaryTerminated |
| 29 | + ) |
| 30 | + }) |
| 31 | + |
| 32 | + it('returns PreliminaryTerminated for preliminaryCancellation stage', () => { |
| 33 | + const lease = factory.tenfastLease.build({ |
| 34 | + stage: 'preliminaryCancellation', |
| 35 | + signed: true, |
| 36 | + startDate: sub(new Date(), { days: 30 }), |
| 37 | + endDate: add(new Date(), { days: 30 }), |
| 38 | + }) |
| 39 | + |
| 40 | + expect(mapToOnecoreLease(lease).status).toBe( |
| 41 | + LeaseStatus.PreliminaryTerminated |
| 42 | + ) |
| 43 | + }) |
| 44 | + |
| 45 | + it('returns Ended for cancelled lease with past end date', () => { |
| 46 | + const lease = factory.tenfastLease.build({ |
| 47 | + stage: 'cancelled', |
| 48 | + signed: true, |
| 49 | + startDate: sub(new Date(), { days: 60 }), |
| 50 | + endDate: sub(new Date(), { days: 1 }), |
| 51 | + }) |
| 52 | + |
| 53 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.Ended) |
| 54 | + }) |
| 55 | + |
| 56 | + it('returns Ended for archived lease with past end date', () => { |
| 57 | + const lease = factory.tenfastLease.build({ |
| 58 | + stage: 'archived', |
| 59 | + signed: true, |
| 60 | + startDate: sub(new Date(), { days: 60 }), |
| 61 | + endDate: sub(new Date(), { days: 1 }), |
| 62 | + }) |
| 63 | + |
| 64 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.Ended) |
| 65 | + }) |
| 66 | + |
| 67 | + it('returns AboutToEnd for lease with future end date', () => { |
| 68 | + const lease = factory.tenfastLease.build({ |
| 69 | + stage: 'cancelled', |
| 70 | + signed: true, |
| 71 | + startDate: sub(new Date(), { days: 30 }), |
| 72 | + endDate: add(new Date(), { days: 30 }), |
| 73 | + }) |
| 74 | + |
| 75 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.AboutToEnd) |
| 76 | + }) |
| 77 | + |
| 78 | + it('returns Upcoming for signed lease with future start date', () => { |
| 79 | + const lease = factory.tenfastLease.build({ |
| 80 | + stage: 'signed', |
| 81 | + signed: true, |
| 82 | + startDate: add(new Date(), { days: 1 }), |
| 83 | + endDate: null, |
| 84 | + }) |
| 85 | + |
| 86 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.Upcoming) |
| 87 | + }) |
| 88 | + |
| 89 | + it('returns Current for signed lease with past start date and no end date', () => { |
| 90 | + const lease = factory.tenfastLease.build({ |
| 91 | + stage: 'signed', |
| 92 | + signed: true, |
| 93 | + startDate: sub(new Date(), { days: 30 }), |
| 94 | + endDate: null, |
| 95 | + }) |
| 96 | + |
| 97 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.Current) |
| 98 | + }) |
| 99 | + |
| 100 | + it('returns Current as fallback for unexpected stage', () => { |
| 101 | + const lease = factory.tenfastLease.build({ |
| 102 | + stage: 'unknownStage', |
| 103 | + signed: false, |
| 104 | + startDate: sub(new Date(), { days: 30 }), |
| 105 | + endDate: null, |
| 106 | + }) |
| 107 | + |
| 108 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.Current) |
| 109 | + }) |
| 110 | + |
| 111 | + it('prioritizes PendingSignature over other statuses', () => { |
| 112 | + // A signingInProgress lease with a future end date could match AboutToEnd, |
| 113 | + // but PendingSignature should take priority |
| 114 | + const lease = factory.tenfastLease.build({ |
| 115 | + stage: 'signingInProgress', |
| 116 | + signed: false, |
| 117 | + startDate: sub(new Date(), { days: 1 }), |
| 118 | + endDate: add(new Date(), { days: 30 }), |
| 119 | + }) |
| 120 | + |
| 121 | + expect(mapToOnecoreLease(lease).status).toBe(LeaseStatus.PendingSignature) |
| 122 | + }) |
| 123 | + |
| 124 | + it('prioritizes PreliminaryTerminated over AboutToEnd', () => { |
| 125 | + // A requestedCancellation lease with a future end date could match AboutToEnd, |
| 126 | + // but PreliminaryTerminated should take priority |
| 127 | + const lease = factory.tenfastLease.build({ |
| 128 | + stage: 'requestedCancellation', |
| 129 | + signed: true, |
| 130 | + startDate: sub(new Date(), { days: 1 }), |
| 131 | + endDate: add(new Date(), { days: 30 }), |
| 132 | + }) |
| 133 | + |
| 134 | + expect(mapToOnecoreLease(lease).status).toBe( |
| 135 | + LeaseStatus.PreliminaryTerminated |
| 136 | + ) |
| 137 | + }) |
| 138 | +}) |
0 commit comments