Skip to content

Commit

Permalink
[FIX] add tests send confirmation mail at ticket creation from mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Aug 31, 2024
1 parent b22a003 commit 915b047
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time

from odoo.addons.test_mail.tests.test_mail_gateway import MAIL_TEMPLATE

from .common import TestHelpdeskTicketBase


Expand Down Expand Up @@ -131,3 +133,73 @@ def test_ticket_without_team(self):
}
)
self.assertEqual(self.new_stage, new_ticket.stage_id)

def test_create_ticket_with_mail_template(self):
new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new")
new_stage.team_ids = [(6, 0, [self.team_a.id])]
new_stage.mail_template_id = self.env.ref(
"helpdesk_mgmt.closed_ticket_template"
)
ticket = self.env["helpdesk.ticket"].create(
{
"name": "I'm a robot, hello",
"team_id": self.team_a.id,
"stage_id": new_stage.id,
"description": "Description",
}
)
ticket_good_reception = ticket.message_ids.filtered(
lambda m: m.message_type == "email"
)
self.assertIn("closed", ticket_good_reception.subject)

def test_create_ticket_from_alias_mail(self):
server = self.env["fetchmail.server"].create(
{
"name": "Demo server",
"server_type": "pop",
"server": "pop3.example.com",
}
)
self.env["mail.alias"].create(
{
"alias_name": "team_a_alias",
"alias_model_id": self.env.ref(
"helpdesk_mgmt.model_helpdesk_ticket"
).id,
"alias_contact": "everyone",
"alias_defaults": {"team_id": self.team_a.id},
"alias_parent_model_id": self.env.ref(
"helpdesk_mgmt.model_helpdesk_ticket_team"
).id,
}
)
new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new")
new_stage.team_ids = [(6, 0, [self.team_a.id])]
new_stage.mail_template_id = self.env.ref(
"helpdesk_mgmt.closed_ticket_template"
)
email = "[email protected]"

self.env["mail.thread"]
.with_context(default_fetchmail_server_id=server.id)
.message_process(
server.object_id.model,
MAIL_TEMPLATE.format(
return_path=email,
email_from=email,
to="[email protected]",
cc="[email protected]",
subject="Hello Ticket",
extra="",
msg_id="<[email protected]>",
),
)

ticket = self.env["helpdesk.ticket"].search([("name", "=", "Hello Ticket")])
self.assertEqual(len(ticket.message_ids), 2)
ticket_good_reception = ticket.message_ids.filtered(
lambda m: m.message_type == "email" and m.email_from != email
)
self.assertEqual(len(ticket_good_reception), 1)
self.assertIn("closed", ticket_good_reception.subject)

0 comments on commit 915b047

Please sign in to comment.