-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
148 lines (140 loc) · 4.97 KB
/
Copy pathjest.setup.js
File metadata and controls
148 lines (140 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Mock environment variables for testing
process.env.OPENAI_API_KEY = 'test-api-key';
process.env.NODE_ENV = 'test';
// Mock OpenAI
const mockOpenAI = jest.fn().mockImplementation(() => ({
chat: {
completions: {
create: jest.fn().mockImplementation((params) => {
// Check if this is a metrics extraction call
const messages = params.messages;
const lastMessage = messages[messages.length - 1];
if (lastMessage.content.includes('key financial metrics')) {
// Return metrics array for extractKeyMetrics
return Promise.resolve({
choices: [{
message: {
content: JSON.stringify([
'monthly_recurring_revenue',
'customer_acquisition_cost',
'churn_rate',
'lifetime_value'
])
}
}]
});
} else {
// Return business classification for classifyBusiness
return Promise.resolve({
choices: [{
message: {
content: JSON.stringify({
models: [{
type: 'saas',
subtype: 'b2b',
confidence: 0.95,
characteristics: ['subscription', 'software', 'b2b']
}],
intents: {
currency: 'USD',
startDate: '2024-01-01',
timeGranularity: 'monthly',
units: 'users',
taxRegime: 'US corporate',
geographicScope: 'national',
planningHorizon: 60,
keyDrivers: ['revenue_growth', 'churn_rate']
},
drivers: ['revenue_growth', 'customer_acquisition_cost', 'churn_rate'],
confidence: 0.9
})
}
}]
});
}
})
}
}
}));
// Mock the openai module
jest.mock('openai', () => {
const mockModule = mockOpenAI;
mockModule.default = mockOpenAI;
mockModule.OpenAI = mockOpenAI;
return mockModule;
});
// Mock better-sqlite3
jest.mock('better-sqlite3', () => {
return jest.fn().mockImplementation(() => ({
pragma: jest.fn(),
exec: jest.fn(),
prepare: jest.fn().mockReturnValue({
all: jest.fn().mockReturnValue([]),
get: jest.fn().mockReturnValue(null),
run: jest.fn()
}),
close: jest.fn()
}));
});
// Mock fs for file operations
jest.mock('fs', () => ({
existsSync: jest.fn().mockReturnValue(false),
mkdirSync: jest.fn(),
writeFileSync: jest.fn(),
readFileSync: jest.fn().mockReturnValue(Buffer.from('test')),
unlinkSync: jest.fn(),
rmdirSync: jest.fn(),
readdirSync: jest.fn().mockReturnValue([]),
createWriteStream: jest.fn().mockReturnValue({
on: jest.fn().mockReturnThis(),
write: jest.fn(),
end: jest.fn()
})
}));
// Mock archiver
jest.mock('archiver', () => {
return jest.fn().mockImplementation(() => ({
pipe: jest.fn().mockReturnThis(),
on: jest.fn().mockReturnThis(),
file: jest.fn().mockReturnThis(),
finalize: jest.fn()
}));
});
// Mock ExcelJS
jest.mock('exceljs', () => {
const mockWorkbook = jest.fn().mockImplementation(() => ({
creator: '',
lastModifiedBy: '',
created: new Date(),
modified: new Date(),
addWorksheet: jest.fn().mockReturnValue({
columns: [],
addRow: jest.fn(),
getRow: jest.fn().mockReturnValue({
font: {},
fill: {},
eachCell: jest.fn(),
eachRow: jest.fn()
}),
eachRow: jest.fn(),
eachCell: jest.fn(),
rowCount: 10
}),
getWorksheet: jest.fn().mockReturnValue({
rowCount: 10,
getCell: jest.fn().mockReturnValue({
formula: ''
})
}),
defineName: jest.fn(),
xlsx: {
writeBuffer: jest.fn().mockResolvedValue(Buffer.from('test'.repeat(1000)))
}
}));
return {
default: {
Workbook: mockWorkbook
},
Workbook: mockWorkbook
};
});