Fix: stamp semana_iniciada_em when campaign first transitions to 'rodando'
Previously, setCampaignStatus did not set semana_iniciada_em, causing
escalateWeeklyLimits to bail early (if (!campaign.semana_iniciada_em) continue).
Now when a campaign transitions to 'rodando' for the first time, semana_iniciada_em
is set to datetime('now'). Subsequent rodando transitions leave it unchanged
(using COALESCE to preserve first-run timestamp).
Regression tests confirm:
- First transition to 'rodando' stamps semana_iniciada_em
- Subsequent transitions do not reset the timestamp
- resumeCampaign continues to work correctly (pause/resume cycle)
- All 105 tests pass
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
fb2cd75a56
commit
577f48ab19
@@ -50,6 +50,35 @@ test('setCampaignStatus pausa e resumeCampaign retoma limpando o motivo', () =>
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('setCampaignStatus rodando stamps semana_iniciada_em on first transition', () => {
|
||||
const db = openDb(':memory:');
|
||||
const campanha = createCampaign(db, campanhaBase());
|
||||
assert.equal(campanha.semana_iniciada_em, null);
|
||||
|
||||
const rodando = setCampaignStatus(db, campanha.id, 'rodando');
|
||||
assert.notEqual(rodando.semana_iniciada_em, null, 'semana_iniciada_em should be set on first rodando transition');
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('setCampaignStatus rodando does not reset already-set semana_iniciada_em', () => {
|
||||
const db = openDb(':memory:');
|
||||
const campanha = createCampaign(db, campanhaBase());
|
||||
|
||||
// Set to rodando first time, which stamps semana_iniciada_em
|
||||
setCampaignStatus(db, campanha.id, 'rodando');
|
||||
|
||||
// Manually set to a known past value via raw SQL
|
||||
const knownTime = '2026-07-15 10:00:00';
|
||||
db.prepare(`UPDATE outreach_campaigns SET semana_iniciada_em = ? WHERE id = ?`).run(knownTime, campanha.id);
|
||||
|
||||
// Call setCampaignStatus again while already 'rodando'
|
||||
const unchanged = setCampaignStatus(db, campanha.id, 'rodando');
|
||||
|
||||
// Verify semana_iniciada_em was not changed
|
||||
assert.equal(unchanged.semana_iniciada_em, knownTime, 'semana_iniciada_em should not be reset on subsequent rodando calls');
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('resumeCampaign nao faz nada se a campanha nao estiver pausada', () => {
|
||||
const db = openDb(':memory:');
|
||||
const campanha = createCampaign(db, campanhaBase());
|
||||
|
||||
Reference in New Issue
Block a user