-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sync.ts
More file actions
86 lines (76 loc) · 3.1 KB
/
test-sync.ts
File metadata and controls
86 lines (76 loc) · 3.1 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
// Load environment variables first
import * as dotenv from 'dotenv';
dotenv.config();
console.log('Environment loaded, SLACK_WEBHOOK_URL exists:', Boolean(process.env.SLACK_WEBHOOK_URL));
import * as slackService from './src/services/slack';
import { Lead, SharpSpringLead } from './src/types';
async function testSyncFlow() {
console.log('Testing sync flow with mock data...');
// Create a mock SharpSpring lead
const mockSharpSpringLead: SharpSpringLead = {
id: 'mock-ss-123',
firstName: 'John',
lastName: 'Doe',
emailAddress: 'john.doe@example.com',
phoneNumber: '555-123-4567',
companyName: 'Acme Corporation',
title: 'CEO',
leadScore: '60',
leadStatus: 'New',
time_frame_5eceb4e7d9474: '1-3 months',
initial_lead_source_5ecff3dcb9ec7: 'Website Contact Form',
createTimestamp: new Date().toISOString(),
updateTimestamp: new Date().toISOString(),
isCustomer: '0',
isQualified: '1',
website: 'https://acme.example.com',
city: 'Boston',
state: 'MA',
zipcode: '02108'
};
// Create a mock Lead object (similar to what would be saved in Supabase)
const mockLead: Lead = {
id: 'mock-lead-uuid-123',
sharpspring_id: mockSharpSpringLead.id,
name: `${mockSharpSpringLead.firstName} ${mockSharpSpringLead.lastName}`,
email: mockSharpSpringLead.emailAddress,
phone: mockSharpSpringLead.phoneNumber,
score: 75, // Simulated score after calculation
tags: ['website', 'high-intent'],
company_name: mockSharpSpringLead.companyName,
title: mockSharpSpringLead.title,
website: mockSharpSpringLead.website,
lead_status: mockSharpSpringLead.leadStatus,
is_customer: false,
is_qualified: true,
time_frame: mockSharpSpringLead.time_frame_5eceb4e7d9474,
city: mockSharpSpringLead.city,
state: mockSharpSpringLead.state,
zipcode: mockSharpSpringLead.zipcode,
lead_source: null,
initial_lead_source: mockSharpSpringLead.initial_lead_source_5ecff3dcb9ec7,
ss_lead_score: parseInt(mockSharpSpringLead.leadScore, 10),
ss_create_timestamp: mockSharpSpringLead.createTimestamp,
ss_update_timestamp: mockSharpSpringLead.updateTimestamp,
last_contacted: null,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString()
};
try {
// Test new lead notification
console.log('\n📤 Sending new lead notification (similar to what happens in sync-leads.ts)...');
await slackService.sendNewLeadNotification(mockLead, mockLead.score);
console.log('✅ Notification sent! Check your Slack app.');
// Wait a moment
await new Promise(resolve => setTimeout(resolve, 1000));
// Test high score alert
console.log('\n📤 Sending high score alert (similar to threshold crossing)...');
await slackService.sendHighScoreAlert(mockLead, mockLead.score);
console.log('✅ High score alert sent! Check your Slack app.');
console.log('\n✨ Test completed successfully!');
} catch (error) {
console.error('Error during test:', error);
}
}
// Run the test
testSyncFlow().catch(error => console.error('Unhandled error:', error));