@elevasis/core 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,189 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ CRM_PIPELINE_DEFINITION,
4
+ CRM_DISCOVERY_REPLIED_STATE,
5
+ CRM_DISCOVERY_LINK_SENT_STATE,
6
+ CRM_DISCOVERY_NUDGING_STATE,
7
+ CRM_DISCOVERY_BOOKING_CANCELLED_STATE,
8
+ CRM_REPLY_SENT_STATE,
9
+ CRM_FOLLOWUP_1_SENT_STATE,
10
+ CRM_FOLLOWUP_2_SENT_STATE,
11
+ CRM_FOLLOWUP_3_SENT_STATE,
12
+ getValidStatesForStage,
13
+ findPipeline,
14
+ ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE,
15
+ ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE,
16
+ LEAD_GEN_PIPELINE_DEFINITIONS
17
+ } from './sales'
18
+
19
+ describe('CRM_PIPELINE_DEFINITION', () => {
20
+ it('has pipelineKey "crm"', () => {
21
+ expect(CRM_PIPELINE_DEFINITION.pipelineKey).toBe('crm')
22
+ })
23
+
24
+ it('has entityKey "crm.deal"', () => {
25
+ expect(CRM_PIPELINE_DEFINITION.entityKey).toBe('crm.deal')
26
+ })
27
+
28
+ it('has exactly 6 stages', () => {
29
+ expect(CRM_PIPELINE_DEFINITION.stages).toHaveLength(6)
30
+ })
31
+
32
+ it('stage keys are interested, proposal, closing, closed_won, closed_lost, nurturing in order', () => {
33
+ const keys = CRM_PIPELINE_DEFINITION.stages.map((s) => s.stageKey)
34
+ expect(keys).toEqual(['interested', 'proposal', 'closing', 'closed_won', 'closed_lost', 'nurturing'])
35
+ })
36
+
37
+ it('interested stage has exactly 8 states', () => {
38
+ const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')
39
+ expect(interested?.states).toHaveLength(8)
40
+ })
41
+
42
+ it('interested stage contains all 8 expected state constants', () => {
43
+ const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')!
44
+ const stateKeys = interested.states.map((s) => s.stateKey)
45
+ expect(stateKeys).toContain(CRM_DISCOVERY_REPLIED_STATE.stateKey)
46
+ expect(stateKeys).toContain(CRM_DISCOVERY_LINK_SENT_STATE.stateKey)
47
+ expect(stateKeys).toContain(CRM_DISCOVERY_NUDGING_STATE.stateKey)
48
+ expect(stateKeys).toContain(CRM_DISCOVERY_BOOKING_CANCELLED_STATE.stateKey)
49
+ expect(stateKeys).toContain(CRM_REPLY_SENT_STATE.stateKey)
50
+ expect(stateKeys).toContain(CRM_FOLLOWUP_1_SENT_STATE.stateKey)
51
+ expect(stateKeys).toContain(CRM_FOLLOWUP_2_SENT_STATE.stateKey)
52
+ expect(stateKeys).toContain(CRM_FOLLOWUP_3_SENT_STATE.stateKey)
53
+ })
54
+
55
+ it('interested stage states reference the exported constants by identity', () => {
56
+ const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')!
57
+ expect(interested.states).toContain(CRM_DISCOVERY_REPLIED_STATE)
58
+ expect(interested.states).toContain(CRM_FOLLOWUP_3_SENT_STATE)
59
+ })
60
+
61
+ it.each(['proposal', 'closing', 'closed_won', 'closed_lost', 'nurturing'])(
62
+ '%s stage has an empty states array',
63
+ (stageKey) => {
64
+ const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === stageKey)
65
+ expect(stage).toBeDefined()
66
+ expect(stage?.states).toHaveLength(0)
67
+ }
68
+ )
69
+
70
+ it('closed_won stage has empty states array', () => {
71
+ const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'closed_won')
72
+ expect(stage?.states).toEqual([])
73
+ })
74
+
75
+ it('closed_lost stage has empty states array', () => {
76
+ const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'closed_lost')
77
+ expect(stage?.states).toEqual([])
78
+ })
79
+ })
80
+
81
+ describe('CRM state constant shapes', () => {
82
+ it('CRM_DISCOVERY_REPLIED_STATE has correct stateKey and label', () => {
83
+ expect(CRM_DISCOVERY_REPLIED_STATE).toEqual({ stateKey: 'discovery_replied', label: 'Discovery Replied' })
84
+ })
85
+
86
+ it('CRM_FOLLOWUP_1_SENT_STATE has correct stateKey and label', () => {
87
+ expect(CRM_FOLLOWUP_1_SENT_STATE).toEqual({ stateKey: 'followup_1_sent', label: 'Follow-up 1 Sent' })
88
+ })
89
+
90
+ it('CRM_FOLLOWUP_2_SENT_STATE has correct stateKey and label', () => {
91
+ expect(CRM_FOLLOWUP_2_SENT_STATE).toEqual({ stateKey: 'followup_2_sent', label: 'Follow-up 2 Sent' })
92
+ })
93
+
94
+ it('CRM_FOLLOWUP_3_SENT_STATE has correct stateKey and label', () => {
95
+ expect(CRM_FOLLOWUP_3_SENT_STATE).toEqual({ stateKey: 'followup_3_sent', label: 'Follow-up 3 Sent' })
96
+ })
97
+ })
98
+
99
+ describe('getValidStatesForStage', () => {
100
+ it('returns all 8 states for the interested stage', () => {
101
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'interested')
102
+ expect(states).toHaveLength(8)
103
+ expect(states.map((s) => s.stateKey)).toContain('discovery_replied')
104
+ expect(states.map((s) => s.stateKey)).toContain('followup_3_sent')
105
+ })
106
+
107
+ it('returns empty array for the proposal stage (no states defined)', () => {
108
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'proposal')
109
+ expect(states).toEqual([])
110
+ })
111
+
112
+ it('returns empty array for the closing stage (no states defined)', () => {
113
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closing')
114
+ expect(states).toEqual([])
115
+ })
116
+
117
+ it('returns empty array for closed_won stage', () => {
118
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closed_won')
119
+ expect(states).toEqual([])
120
+ })
121
+
122
+ it('returns empty array for closed_lost stage', () => {
123
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closed_lost')
124
+ expect(states).toEqual([])
125
+ })
126
+
127
+ it('returns empty array for nurturing stage (no states defined)', () => {
128
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'nurturing')
129
+ expect(states).toEqual([])
130
+ })
131
+
132
+ it('returns empty array for an unknown stage key', () => {
133
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'unknown_stage')
134
+ expect(states).toEqual([])
135
+ })
136
+
137
+ it('returns empty array for an empty string stage key', () => {
138
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, '')
139
+ expect(states).toEqual([])
140
+ })
141
+
142
+ it('is case-sensitive — "Interested" does not match "interested"', () => {
143
+ const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'Interested')
144
+ expect(states).toEqual([])
145
+ })
146
+
147
+ it('works with the lead-gen member pipeline for known stage', () => {
148
+ const states = getValidStatesForStage(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE, 'outreach')
149
+ expect(states.length).toBeGreaterThan(0)
150
+ expect(states.map((s) => s.stateKey)).toContain('personalized')
151
+ })
152
+
153
+ it('works with the lead-gen member pipeline for unknown stage', () => {
154
+ const states = getValidStatesForStage(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE, 'nonexistent')
155
+ expect(states).toEqual([])
156
+ })
157
+ })
158
+
159
+ describe('findPipeline', () => {
160
+ it('finds a pipeline by pipelineKey when present', () => {
161
+ const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'lead-gen')
162
+ expect(found).toBe(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
163
+ })
164
+
165
+ it('returns undefined for an unknown pipelineKey', () => {
166
+ const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'crm')
167
+ expect(found).toBeUndefined()
168
+ })
169
+
170
+ it('returns undefined for an empty array', () => {
171
+ const found = findPipeline([], 'lead-gen')
172
+ expect(found).toBeUndefined()
173
+ })
174
+ })
175
+
176
+ describe('LEAD_GEN_PIPELINE_DEFINITIONS', () => {
177
+ it('has entries for acq.list-member and acq.list-company', () => {
178
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-member')
179
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-company')
180
+ })
181
+
182
+ it('acq.list-member entry contains the ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE', () => {
183
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member']).toContain(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
184
+ })
185
+
186
+ it('acq.list-company entry contains the ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE', () => {
187
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-company']).toContain(ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE)
188
+ })
189
+ })