Overview
Thetest.js file provides a standalone testing environment that simulates the event synchronization process without making actual API calls to HubSpot. This allows you to:
- Validate pipeline mapping logic
- Test date filtering
- Verify deal creation payloads
- Debug event processing without affecting production data
Test Script Structure
The test script (test.js) mirrors the main function’s logic with mock data.
Mock Events Data
The test includes 5 sample events (test.js:4-119) that cover different scenarios:
Test Scenarios
The mock data covers these key test cases:Event with default pipeline
Event with default pipeline
Event: “Test” (line 7)Tests the fallback behavior when
pipeline is set to "default".Expected outcome:- Pipeline:
"default" - Deal stage:
"appointmentscheduled"
Event missing pipeline property
Event missing pipeline property
Event: “20251202 Prueba TI 7” (line 31)Tests behavior when
customProperties doesn’t include a pipeline field.Expected outcome:- Pipeline defaults to
"default" - Console warning:
"⚠️ No se encontró la propiedad 'pipeline' en customProperties"
Event with mapped pipeline (732960029)
Event with mapped pipeline (732960029)
Event: “Evento con pipeline 732960029” (line 54)Tests a valid pipeline ID that exists in the mapping.Expected outcome:
- Pipeline:
"732960029" - Deal stage:
"1067986567"
Event with mapped pipeline (733263424)
Event with mapped pipeline (733263424)
Event: “Evento con pipeline 733263424” (line 76)Tests another valid pipeline mapping.Expected outcome:
- Pipeline:
"733263424" - Deal stage:
"1068046680"
Event with unmapped pipeline
Event with unmapped pipeline
Event: “Evento con pipeline no mapeado” (line 98)Tests behavior when pipeline ID (
999888777) doesn’t exist in the mapping.Expected outcome:- Pipeline:
"999888777" - Deal stage falls back to
"appointmentscheduled" - Console warning:
"⚠️ Pipeline '999888777' no encontrado en mapeo"
Running the Test
Execute the Test Script
Run the test from your terminal:Expected Output
A successful test run produces output like this:Interpreting Test Output
Console Log Symbols
The test uses emoji symbols to indicate different types of messages:| Symbol | Meaning | Example |
|---|---|---|
| 🚀 | Process started | 🚀 Iniciando test... |
| 📊 | Data processing | 📊 Procesando respuesta... |
| 📍 | Information point | 📍 Total de eventos: 5 |
| 📅 | Date filtering | 📅 Eventos encontrados hoy: 5 |
| 📋 | Pipeline info | 📋 Pipeline encontrado: default |
| 🎯 | Deal stage assigned | 🎯 Deal stage asignado: 1067986567 |
| ✅ | Success | ✅ Deal simulado creado |
| ⚠️ | Warning | ⚠️ Pipeline no encontrado |
| ❌ | Error | ❌ Error en el test |
Key Functions Tested
1. getPipelineFromCustomProperties (test.js:123-141)
Extracts the pipeline value from the customProperties array:
2. filterEventsByToday (test.js:144-158)
Filters events created on the current day:
The test script sets all mock events’
createdAt to “2025-11-14” to ensure they pass the date filter. In production, only events created on the execution day are processed.3. getDealStageByPipeline (test.js:161-184)
Maps pipeline values to deal stages:
4. simulateCreateDeal (test.js:187-217)
Simulates deal creation without making API calls:
Modifying Test Data
To test different scenarios, modify themockEventsResponse object:
Adding a New Test Event
Add a new event object to theresults array:
Testing Date Filtering
To test the date filter, change thecreatedAt timestamp:
Testing Missing Properties
Test how the script handles missing data:Validating Results
After running the test, verify:- Correct event count: All events with today’s date should be processed
- Pipeline extraction: Check that pipelines are correctly extracted from
customProperties - Deal stage mapping: Verify that each pipeline maps to the expected deal stage
- Default values: Confirm that missing pipelines default to
"default"and deal stage to"appointmentscheduled" - Data completeness: Ensure all event properties are correctly mapped to deal properties
Next Steps
Troubleshooting
Learn how to debug common issues and interpret error messages