realtimex-crm 0.11.0 → 0.11.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realtimex-crm",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,54 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { getDealsByStage } from './stages';
3
+ import type { Deal } from '../types';
4
+
5
+ describe('getDealsByStage', () => {
6
+ const mockDealStages = [
7
+ { value: 'stage1', label: 'Stage 1' },
8
+ { value: 'stage2', label: 'Stage 2' },
9
+ ];
10
+
11
+ it('should group deals by stage', () => {
12
+ const deals = [
13
+ { id: 1, stage: 'stage1', index: 0, name: 'Deal 1' },
14
+ { id: 2, stage: 'stage2', index: 0, name: 'Deal 2' },
15
+ { id: 3, stage: 'stage1', index: 1, name: 'Deal 3' },
16
+ ] as unknown as Deal[];
17
+
18
+ const result = getDealsByStage(deals, mockDealStages);
19
+
20
+ expect(result['stage1']).toHaveLength(2);
21
+ expect(result['stage2']).toHaveLength(1);
22
+ expect(result['stage1'].map(d => d.name)).toEqual(['Deal 1', 'Deal 3']);
23
+ });
24
+
25
+ it('should ignore deals with unknown stages instead of crashing', () => {
26
+ const deals = [
27
+ { id: 1, stage: 'stage1', index: 0, name: 'Deal 1' },
28
+ { id: 4, stage: 'unknown_stage', index: 0, name: 'Deal 4' }, // Malformed data
29
+ ] as unknown as Deal[];
30
+
31
+ const result = getDealsByStage(deals, mockDealStages);
32
+
33
+ expect(result['stage1']).toHaveLength(1);
34
+ expect(result).not.toHaveProperty('unknown_stage');
35
+ });
36
+
37
+ it('should handle empty deal list', () => {
38
+ const deals: Deal[] = [];
39
+ const result = getDealsByStage(deals, mockDealStages);
40
+ expect(result['stage1']).toEqual([]);
41
+ expect(result['stage2']).toEqual([]);
42
+ });
43
+
44
+ it('should sort deals by index', () => {
45
+ const deals = [
46
+ { id: 1, stage: 'stage1', index: 2, name: 'Deal 1' },
47
+ { id: 3, stage: 'stage1', index: 1, name: 'Deal 3' },
48
+ ] as unknown as Deal[];
49
+
50
+ const result = getDealsByStage(deals, mockDealStages);
51
+ expect(result['stage1'][0].index).toBe(1);
52
+ expect(result['stage1'][1].index).toBe(2);
53
+ });
54
+ });
@@ -10,7 +10,9 @@ export const getDealsByStage = (
10
10
  if (!dealStages) return {};
11
11
  const dealsByStage: Record<Deal["stage"], Deal[]> = unorderedDeals.reduce(
12
12
  (acc, deal) => {
13
- acc[deal.stage].push(deal);
13
+ if (acc[deal.stage]) {
14
+ acc[deal.stage].push(deal);
15
+ }
14
16
  return acc;
15
17
  },
16
18
  dealStages.reduce(