feat(manager): allow manager to create auto-approved campaigns and tests from templates
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
A manager organizes and validates work, so their own campaigns skip the draft -> submit -> pending_approval queue and go straight to active with the start_date they provide (they're the same role that would otherwise approve it). Manager can also now create tests from the catalog, same as red_lead/blue_lead.
This commit is contained in:
@@ -346,5 +346,74 @@ def test_create_campaign_payload_has_no_start_date_field(api, db, red_lead_heade
|
||||
json={"name": "No date campaign", "start_date": "2026-01-01"},
|
||||
)
|
||||
assert resp.status_code == 201
|
||||
# start_date silently ignored — only the manager can ever set it, via /approve
|
||||
# start_date silently ignored for a lead — only a manager's own
|
||||
# creation (or a later /approve) can ever set it.
|
||||
assert resp.json()["start_date"] is None
|
||||
|
||||
|
||||
def test_manager_can_create_campaign_auto_approved(api, db, manager_headers):
|
||||
"""A manager is the same role that would otherwise approve a campaign,
|
||||
so their own campaign skips the draft -> submit -> pending_approval
|
||||
queue and goes straight to active with the start_date they provide."""
|
||||
resp = api(
|
||||
"post",
|
||||
"/api/v1/campaigns",
|
||||
manager_headers,
|
||||
json={"name": "Manager-created campaign", "start_date": "2020-01-01T00:00:00"},
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
body = resp.json()
|
||||
assert body["status"] == "active"
|
||||
assert body["start_date"] is not None
|
||||
|
||||
|
||||
def test_manager_campaign_creation_requires_start_date(api, db, manager_headers):
|
||||
resp = api(
|
||||
"post",
|
||||
"/api/v1/campaigns",
|
||||
manager_headers,
|
||||
json={"name": "Manager-created campaign, no date"},
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_manager_creation_creates_jira_tickets_when_start_date_is_due(api, db, manager_headers):
|
||||
with patch(
|
||||
"app.services.jira_service.get_campaign_jira_key", return_value=None
|
||||
) as mock_get_key, patch(
|
||||
"app.services.jira_service.auto_create_campaign_issue", return_value="PT-300"
|
||||
) as mock_create_campaign:
|
||||
resp = api(
|
||||
"post",
|
||||
"/api/v1/campaigns",
|
||||
manager_headers,
|
||||
json={"name": "Manager-created, due now", "start_date": "2020-01-01T00:00:00"},
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
mock_get_key.assert_called_once()
|
||||
mock_create_campaign.assert_called_once()
|
||||
|
||||
|
||||
def test_manager_creation_skips_jira_tickets_when_start_date_is_future(api, db, manager_headers):
|
||||
with patch(
|
||||
"app.services.jira_service.get_campaign_jira_key", return_value=None
|
||||
) as mock_get_key:
|
||||
resp = api(
|
||||
"post",
|
||||
"/api/v1/campaigns",
|
||||
manager_headers,
|
||||
json={"name": "Manager-created, future", "start_date": "2099-01-01T00:00:00"},
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
mock_get_key.assert_not_called()
|
||||
|
||||
|
||||
def test_lead_created_campaign_is_still_draft_not_auto_approved(api, db, red_lead_headers):
|
||||
resp = api(
|
||||
"post",
|
||||
"/api/v1/campaigns",
|
||||
red_lead_headers,
|
||||
json={"name": "Lead-created campaign"},
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
assert resp.json()["status"] == "draft"
|
||||
|
||||
Reference in New Issue
Block a user