diff --git a/README.md b/README.md index ec5d7f80..2e75ff39 100644 --- a/README.md +++ b/README.md @@ -991,7 +991,7 @@ If success, 200 with the list of aliases. Each alias has the following fields: - mailboxes: list of mailbox, contains at least 1 mailbox. - id - email -- (optional) latest_activity: +- (nullable) latest_activity: - action: forward|reply|block|bounced - timestamp - contact: diff --git a/app/api/serializer.py b/app/api/serializer.py index a92d6339..362ed662 100644 --- a/app/api/serializer.py +++ b/app/api/serializer.py @@ -64,6 +64,7 @@ def serialize_alias_info_v2(alias_info: AliasInfo) -> dict: ], "support_pgp": alias_info.alias.mailbox_support_pgp(), "disable_pgp": alias_info.alias.disable_pgp, + "latest_activity": None, } if alias_info.latest_email_log: email_log = alias_info.latest_email_log diff --git a/app/api/views/alias.py b/app/api/views/alias.py index 7263b41b..2d79d6d2 100644 --- a/app/api/views/alias.py +++ b/app/api/views/alias.py @@ -86,7 +86,7 @@ def get_aliases_v2(): - mailboxes - support_pgp - disable_pgp - - (optional) latest_activity: + - latest_activity: null if no activity. - timestamp - action: forward|reply|block|bounced - contact: diff --git a/tests/api/test_alias.py b/tests/api/test_alias.py index 2848172d..ecf2df14 100644 --- a/tests/api/test_alias.py +++ b/tests/api/test_alias.py @@ -119,7 +119,33 @@ def test_get_aliases_v2(flask_client): a1 = Alias.create_new(user, "prefix1") db.session.commit() - # add activity for a0 + # << Aliases have no activity >> + r = flask_client.get( + url_for("api.get_aliases_v2", page_id=0), + headers={"Authentication": api_key.code}, + ) + assert r.status_code == 200 + + r0 = r.json["aliases"][0] + assert "name" in r0 + + # make sure a1 is returned before a0 + assert r0["email"].startswith("prefix1") + assert "id" in r0["mailbox"] + assert "email" in r0["mailbox"] + + assert r0["mailboxes"] + for mailbox in r0["mailboxes"]: + assert "id" in mailbox + assert "email" in mailbox + + assert "support_pgp" in r0 + assert not r0["support_pgp"] + + assert "disable_pgp" in r0 + assert not r0["disable_pgp"] + + # << Alias has some activities >> c0 = Contact.create( user_id=user.id, alias_id=a0.id, @@ -148,36 +174,8 @@ def test_get_aliases_v2(flask_client): ) assert r.status_code == 200 - # make sure a1 is returned before a0 r0 = r.json["aliases"][0] - # r0 will have the following format - # { - # "creation_date": "2020-04-25 21:10:01+00:00", - # "creation_timestamp": 1587849001, - # "email": "prefix1.yeah@sl.local", - # "enabled": true, - # "id": 3, - # "name": "Hey hey", - # "latest_activity": { - # "action": "forward", - # "contact": { - # "email": "c1@example.com", - # "name": null, - # "reverse_alias": "\"c1 at example.com\" " - # }, - # "timestamp": 1587849001 - # }, - # "mailbox": { - # "email": "a@b.c", - # "id": 1 - # }, - # "nb_block": 0, - # "nb_forward": 1, - # "nb_reply": 0, - # "note": null - # } - assert "name" in r0 - assert r0["email"].startswith("prefix1") + assert r0["latest_activity"]["action"] == "forward" assert "timestamp" in r0["latest_activity"] @@ -185,20 +183,6 @@ def test_get_aliases_v2(flask_client): assert "name" in r0["latest_activity"]["contact"] assert "reverse_alias" in r0["latest_activity"]["contact"] - assert "id" in r0["mailbox"] - assert "email" in r0["mailbox"] - - assert r0["mailboxes"] - for mailbox in r0["mailboxes"]: - assert "id" in mailbox - assert "email" in mailbox - - assert "support_pgp" in r0 - assert not r0["support_pgp"] - - assert "disable_pgp" in r0 - assert not r0["disable_pgp"] - def test_delete_alias(flask_client): user = User.create(