mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 17:35:27 +08:00
return latest_activity=null if there's no activity in GET /api/v2/aliases
This commit is contained in:
parent
92ea8de374
commit
ec1b7dd8b8
4 changed files with 31 additions and 46 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue