Selaa lähdekoodia

return latest_activity=null if there's no activity in GET /api/v2/aliases

Son NK 4 vuotta sitten
vanhempi
commit
ec1b7dd8b8
4 muutettua tiedostoa jossa 31 lisäystä ja 46 poistoa
  1. 1 1
      README.md
  2. 1 0
      app/api/serializer.py
  3. 1 1
      app/api/views/alias.py
  4. 28 44
      tests/api/test_alias.py

+ 1 - 1
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:

+ 1 - 0
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

+ 1 - 1
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:

+ 28 - 44
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\" <re1@SL>"
-    #         },
-    #         "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(