fix: Update contact subscription logic for upsert operations

This commit is contained in:
Dries Augustyns
2026-02-17 10:25:01 +01:00
parent d55dda3127
commit a928666dfc
2 changed files with 17 additions and 4 deletions
@@ -850,6 +850,17 @@ describe('Actions API Integration Tests', () => {
expect(result.data.subscribed).toBeUndefined();
}
});
it('should create new contacts as unsubscribed when subscribed is undefined', async () => {
const newEmail = '[email protected]';
// Send email to new contact without specifying subscribed
const {ContactService} = await import('../../services/ContactService.js');
const contact = await ContactService.upsert(projectId, newEmail, {name: 'Test'}, false);
// Transactional emails should create contacts as unsubscribed by default
expect(contact.subscribed).toBe(false);
});
});
describe('/v1/track endpoint', () => {
@@ -905,9 +916,9 @@ describe('Actions API Integration Tests', () => {
// Track event for new contact without specifying subscribed
const {ContactService} = await import('../../services/ContactService.js');
const contact = await ContactService.upsert(projectId, newEmail, {event: 'test'}, undefined);
const contact = await ContactService.upsert(projectId, newEmail, {event: 'test'}, true);
// New contacts should default to subscribed=true
// Event tracking should create contacts as subscribed by default
expect(contact.subscribed).toBe(true);
});