Skip to content

Commit 6f16fc6

Browse files
committed
Fixed bug in unseen messages route + added timestamp setting in see message route + added tests for unseen messages
1 parent d9a52c6 commit 6f16fc6

File tree

2 files changed

+102
-22
lines changed

2 files changed

+102
-22
lines changed

PyMatcha.postman_collection.json

Lines changed: 95 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4497,6 +4497,46 @@
44974497
},
44984498
"response": []
44994499
},
4500+
{
4501+
"name": "Get unseen messages",
4502+
"event": [
4503+
{
4504+
"listen": "test",
4505+
"script": {
4506+
"id": "f76e158d-1a7b-4047-8703-5788204d3e08",
4507+
"exec": [
4508+
"var response = JSON.parse(responseBody);",
4509+
"",
4510+
"",
4511+
"pm.test(\"Status code is 200\", function () {",
4512+
" pm.response.to.have.status(200);",
4513+
"});",
4514+
"",
4515+
"tests[\"Message is correct\"] = response.new_messages.length == 1",
4516+
"tests[\"New message content is correct\"] = response.new_messages[0].content == \"My Reply\"",
4517+
"tests[\"New message is_seen\"] = response.new_messages[0].is_seen == 0",
4518+
"tests[\"New message seen timestamp is null\"] = response.new_messages[0].seen_timestamp == null"
4519+
],
4520+
"type": "text/javascript"
4521+
}
4522+
}
4523+
],
4524+
"request": {
4525+
"method": "GET",
4526+
"header": [],
4527+
"url": {
4528+
"raw": "{{host}}/messages/unseen",
4529+
"host": [
4530+
"{{host}}"
4531+
],
4532+
"path": [
4533+
"messages",
4534+
"unseen"
4535+
]
4536+
}
4537+
},
4538+
"response": []
4539+
},
45004540
{
45014541
"name": "See unknown user messages",
45024542
"event": [
@@ -4633,6 +4673,43 @@
46334673
}
46344674
},
46354675
"response": []
4676+
},
4677+
{
4678+
"name": "Get unseen messages no new message",
4679+
"event": [
4680+
{
4681+
"listen": "test",
4682+
"script": {
4683+
"id": "dc64c405-ead8-405c-9f31-841290add73a",
4684+
"exec": [
4685+
"var response = JSON.parse(responseBody);",
4686+
"",
4687+
"",
4688+
"pm.test(\"Status code is 200\", function () {",
4689+
" pm.response.to.have.status(200);",
4690+
"});",
4691+
"",
4692+
"tests[\"Message is correct\"] = response.message == \"No new messages.\""
4693+
],
4694+
"type": "text/javascript"
4695+
}
4696+
}
4697+
],
4698+
"request": {
4699+
"method": "GET",
4700+
"header": [],
4701+
"url": {
4702+
"raw": "{{host}}/messages/unseen",
4703+
"host": [
4704+
"{{host}}"
4705+
],
4706+
"path": [
4707+
"messages",
4708+
"unseen"
4709+
]
4710+
}
4711+
},
4712+
"response": []
46364713
}
46374714
],
46384715
"protocolProfileBehavior": {}
@@ -4795,92 +4872,92 @@
47954872
],
47964873
"variable": [
47974874
{
4798-
"id": "51a87d51-b3a6-4cde-9b11-1fe5ad7be7af",
4875+
"id": "d56a13d7-6874-4212-952f-32539a07db40",
47994876
"key": "host",
48004877
"value": "http://127.0.0.1:5000"
48014878
},
48024879
{
4803-
"id": "7cbb58d1-cad3-4e00-915f-53a6c467d991",
4880+
"id": "623be53f-61b5-4d24-8f90-74ddcf0ce4b9",
48044881
"key": "user_id",
48054882
"value": ""
48064883
},
48074884
{
4808-
"id": "693836fa-3848-4780-81c7-ad60a40700ae",
4885+
"id": "14a84e70-a42c-4bda-8986-caf5edd0b131",
48094886
"key": "user_email",
48104887
"value": "foo@example.org"
48114888
},
48124889
{
4813-
"id": "02053d62-a0a9-40bb-8e6f-43d86eb1fa17",
4890+
"id": "bd3f19c8-5e62-40f7-b441-a091762a447a",
48144891
"key": "user_username",
48154892
"value": "foo"
48164893
},
48174894
{
4818-
"id": "760554e4-b902-431a-b29b-03679009434c",
4895+
"id": "e9404b3c-30e4-41e4-802a-17f0b898aa47",
48194896
"key": "user_password",
48204897
"value": "admin"
48214898
},
48224899
{
4823-
"id": "8d73261c-6557-4939-9718-c5f3ed186ea8",
4900+
"id": "3f209e31-a678-406e-9ad7-ae23cfa83ab8",
48244901
"key": "user_firstname",
48254902
"value": "Foo"
48264903
},
48274904
{
4828-
"id": "f7fa880d-6264-44f7-a8ce-c470ff077a83",
4905+
"id": "b2f1c85a-bd1b-49bf-b8e0-0e4328ed95f2",
48294906
"key": "user_lastname",
48304907
"value": "Bar"
48314908
},
48324909
{
4833-
"id": "28f7acd5-c6b0-4e82-a04c-17371197787b",
4910+
"id": "df95c185-4257-4d69-8f80-4e51b6ea84aa",
48344911
"key": "debug_token",
48354912
"value": "xX69jules69Xx"
48364913
},
48374914
{
4838-
"id": "ad555769-0803-4b30-a7a2-fdb9d582fd4d",
4915+
"id": "baac5b67-e6f8-4b44-8d03-9c1de6dba09f",
48394916
"key": "user_access_token",
48404917
"value": ""
48414918
},
48424919
{
4843-
"id": "bd3194a6-e6b3-4f1d-a3f5-bf41341dc093",
4920+
"id": "40cf296c-1333-42e1-970f-13e03d60d1eb",
48444921
"key": "user_refresh_token",
48454922
"value": ""
48464923
},
48474924
{
4848-
"id": "f35b0ce7-b46a-41ac-8c79-efa76178786e",
4925+
"id": "ed652ff2-2c51-413c-9465-9e181d80f0e5",
48494926
"key": "expired_token",
48504927
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU"
48514928
},
48524929
{
4853-
"id": "e22e2d2f-a517-4b9b-890f-9393c8656aed",
4930+
"id": "87d63756-b49d-430e-a5fd-25fc048be13d",
48544931
"key": "user_orientation",
48554932
"value": "heterosexual"
48564933
},
48574934
{
4858-
"id": "2a8b6700-24d1-4ca6-b29c-d022b8a5fb8c",
4935+
"id": "ff3a467c-902b-4129-9bf5-adf5d701b732",
48594936
"key": "user_bio",
48604937
"value": "Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites. Lorem Ipsum best not make any more threats to your website. It will be met with fire and fury like the world has never seen. Does everybody know that pig named Lorem Ipsum? An ‘extremely credible source’ has called my office and told me that Barack Obama’s placeholder text is a fraud."
48614938
},
48624939
{
4863-
"id": "597a56c2-2530-4900-ae36-b3e10175d936",
4940+
"id": "c80b16e5-fc1e-4d2c-b2e3-6cf8340bf274",
48644941
"key": "user_gender",
48654942
"value": "male"
48664943
},
48674944
{
4868-
"id": "3c09e8cb-9e4a-4274-90fe-354196c4c64a",
4945+
"id": "49132f7c-7b3c-40c3-b11f-fdea73fd2acb",
48694946
"key": "user_birthdate",
48704947
"value": "06/04/1998"
48714948
},
48724949
{
4873-
"id": "73a843d0-a43e-4829-92b4-099a8f86ae74",
4950+
"id": "ad9d9ed7-2330-427e-937b-9a93e0504e4a",
48744951
"key": "user_lat",
48754952
"value": "44.8404"
48764953
},
48774954
{
4878-
"id": "3ad8f109-e36f-43dd-9f60-077a4fbe06b8",
4955+
"id": "1f2570ff-5cab-466f-b221-97a79a631165",
48794956
"key": "user_lng",
48804957
"value": "-0.5805"
48814958
},
48824959
{
4883-
"id": "0a23376b-a2a7-4d5c-8cd4-ba2dcbdfbe58",
4960+
"id": "8436114f-4417-4821-8168-8cabee7c69ee",
48844961
"key": "user_ip",
48854962
"value": "77.205.46.181"
48864963
}

backend/PyMatcha/routes/api/messages.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
You should have received a copy of the GNU General Public License
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
19+
import datetime
20+
1921
from flask import Blueprint
2022
from flask import current_app
2123
from flask import request
@@ -35,9 +37,9 @@
3537
messages_bp = Blueprint("messages", __name__)
3638

3739
"""
38-
test get all messages
3940
test more than one conv
40-
test like message
41+
like route
42+
conv with user route
4143
"""
4244

4345

@@ -102,6 +104,7 @@ def see_conversation_messages(with_uid):
102104
if unseen_messages:
103105
for message in unseen_messages:
104106
message.is_seen = True
107+
message.seen_timestamp = datetime.datetime.utcnow()
105108
message.save()
106109
return Success("Messages marked as seen.")
107110

@@ -123,8 +126,8 @@ def like_message(message_id):
123126
@messages_bp.route("/messages/unseen", methods=["GET"])
124127
@jwt_required
125128
def get_new_messages():
126-
message_list = current_user.get_multis(to_id=current_user.id, is_seen=False)
129+
message_list = Message.get_multis(to_id=current_user.id, is_seen=False)
127130
if not message_list:
128-
return Success("No new messages")
131+
return Success("No new messages.")
129132
new_messages = [m.to_dict() for m in message_list]
130133
return SuccessOutput("new_messages", new_messages)

0 commit comments

Comments
 (0)