Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Invite friend minor fixes + added test case (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbanjos authored and rmuhamed committed Dec 29, 2019
1 parent 2ae26fa commit 0267b85
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
Binary file modified doc/build/doctrees/application.doctree
Binary file not shown.
Binary file modified doc/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified doc/build/html/_images/thesheriff_class_diagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions doc/build/html/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ <h2>Outlaw<a class="headerlink" href="#outlaw" title="Permalink to this headline
</dl>
<dl class="method">
<dt id="thesheriff.application.outlaw.invite_friend.InviteFriend.execute">
<code class="sig-name descname">execute</code><span class="sig-paren">(</span><em class="sig-param">request: thesheriff.application.outlaw.request.invite_friend_request.InviteFriendRequest</em><span class="sig-paren">)</span><a class="headerlink" href="#thesheriff.application.outlaw.invite_friend.InviteFriend.execute" title="Permalink to this definition"></a></dt>
<code class="sig-name descname">execute</code><span class="sig-paren">(</span><em class="sig-param">request: thesheriff.application.outlaw.request.invite_friend_request.InviteFriendRequest</em><span class="sig-paren">)</span> &#x2192; thesheriff.domain.mail.mail.Mail<a class="headerlink" href="#thesheriff.application.outlaw.invite_friend.InviteFriend.execute" title="Permalink to this definition"></a></dt>
<dd><p>execute is the actual action of the Invite Friend use case.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>request</strong> (<em>InviteFriendRequest</em>) – The address to write on the TO field.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>No value returned.</p>
<dt class="field-even">Return mail</dt>
<dd class="field-even"><p>Mail.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>NoReturn</p>
<dd class="field-odd"><p><a class="reference internal" href="domain.html#thesheriff.domain.mail.mail.Mail" title="thesheriff.domain.mail.mail.Mail">Mail</a></p>
</dd>
</dl>
</dd></dl>
Expand Down
24 changes: 24 additions & 0 deletions tests/test_invite_friend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from tests.mocks.mock_mail_notifier import MockMailNotifier
from tests.mocks.mock_outlaw_repository import MockOutlawRepository
from thesheriff.application.outlaw.invite_friend import InviteFriend
from thesheriff.application.outlaw.request.invite_friend_request import \
InviteFriendRequest
from thesheriff.domain.outlaw.outlaw import Outlaw


def test_invite_friend():
notifier = MockMailNotifier()
outlaw_repository = MockOutlawRepository()

outlaw = Outlaw("The gang chief", "bad@yopmail.com", 1)
outlaw_repository.add(outlaw)

receiver_email = "receiver@yopmail.com"

invite_friend = InviteFriend(outlaw_repository, notifier)

request = InviteFriendRequest(outlaw.id, receiver_email)
mail = invite_friend.execute(request)

assert mail.sender == outlaw.email
assert mail.receiver == receiver_email
10 changes: 6 additions & 4 deletions thesheriff/application/outlaw/invite_friend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from thesheriff.application.outlaw.request.invite_friend_request import \
InviteFriendRequest
from thesheriff.domain.mail.mail import Mail
from thesheriff.domain.mail.mail_factory import MailFactory
from thesheriff.domain.mail.notifier.mail_notifier import MailNotifier
from thesheriff.domain.outlaw.outlaw import Outlaw
Expand All @@ -26,15 +27,16 @@ def __init__(self, outlaw_repository: OutlawRepository,
self.__outlaw_repository = outlaw_repository
self.__mail_notifier = mail_notifier

def execute(self, request: InviteFriendRequest):
def execute(self, request: InviteFriendRequest) -> Mail:
"""execute is the actual action of the Invite Friend use case.
:param request: The address to write on the TO field.
:type request: InviteFriendRequest
:return: No value returned.
:rtype: NoReturn
:return mail: Mail.
:rtype: Mail
"""
sender_mail = self.__outlaw_repository.of_id(request.outlaw_id).email
receiver_mail = request.mail_address_receiver
mail = MailFactory.mail_invite_friend(sender_mail, receiver_mail)
self.__mail_notifier.send(mail=mail)
self.__mail_notifier.send(mail)
return mail

0 comments on commit 0267b85

Please sign in to comment.