Skip to content

Commit 93c4967

Browse files
committed
Fixed bug in see messages where all messages were seen + added postman test
1 parent 0d9ade3 commit 93c4967

File tree

2 files changed

+164
-28
lines changed

2 files changed

+164
-28
lines changed

PyMatcha.postman_collection.json

Lines changed: 157 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,7 +4368,7 @@
43684368
"response": []
43694369
},
43704370
{
4371-
"name": "Get one conversation",
4371+
"name": "Get conversations after message",
43724372
"event": [
43734373
{
43744374
"listen": "test",
@@ -4459,7 +4459,7 @@
44594459
"response": []
44604460
},
44614461
{
4462-
"name": "Get one conversation after reply",
4462+
"name": "Get conversations after reply",
44634463
"event": [
44644464
{
44654465
"listen": "test",
@@ -4496,6 +4496,143 @@
44964496
}
44974497
},
44984498
"response": []
4499+
},
4500+
{
4501+
"name": "See unknown user messages",
4502+
"event": [
4503+
{
4504+
"listen": "test",
4505+
"script": {
4506+
"id": "fb2d9223-cac3-4d2d-9eea-4356b5a5ea8b",
4507+
"exec": [
4508+
"var response = JSON.parse(responseBody);",
4509+
"",
4510+
"",
4511+
"pm.test(\"Status code is 404\", function () {",
4512+
" pm.response.to.have.status(404);",
4513+
"});",
4514+
"",
4515+
"tests[\"JSON return code is 404\"] = response.code == 404",
4516+
"",
4517+
"tests[\"success is false\"] = response.success == false",
4518+
"tests[\"Message is correct\"] = response.error.message == \"With user -1 not found\"",
4519+
"tests[\"Error type is Bad Request\"] = response.error.type == \"NotFoundError\""
4520+
],
4521+
"type": "text/javascript"
4522+
}
4523+
}
4524+
],
4525+
"request": {
4526+
"method": "POST",
4527+
"header": [],
4528+
"body": {
4529+
"mode": "raw",
4530+
"raw": "{\n \"from_uid\": \"message_me\",\n \"to_uid\": \"{{user_id}}\",\n \"content\": \"My Reply\"\n}",
4531+
"options": {
4532+
"raw": {
4533+
"language": "json"
4534+
}
4535+
}
4536+
},
4537+
"url": {
4538+
"raw": "{{host}}/messages/see/-1",
4539+
"host": [
4540+
"{{host}}"
4541+
],
4542+
"path": [
4543+
"messages",
4544+
"see",
4545+
"-1"
4546+
]
4547+
}
4548+
},
4549+
"response": []
4550+
},
4551+
{
4552+
"name": "See messages from message_me",
4553+
"event": [
4554+
{
4555+
"listen": "test",
4556+
"script": {
4557+
"id": "17b9bbf3-703d-4a97-b512-25c04f8248c9",
4558+
"exec": [
4559+
"var response = JSON.parse(responseBody);",
4560+
"",
4561+
"",
4562+
"pm.test(\"Status code is 200\", function () {",
4563+
" pm.response.to.have.status(200);",
4564+
"});",
4565+
"",
4566+
"tests[\"Message is correct\"] = response.message == \"Messages marked as seen.\""
4567+
],
4568+
"type": "text/javascript"
4569+
}
4570+
}
4571+
],
4572+
"request": {
4573+
"method": "POST",
4574+
"header": [],
4575+
"body": {
4576+
"mode": "raw",
4577+
"raw": "{\n \"from_uid\": \"message_me\",\n \"to_uid\": \"{{user_id}}\",\n \"content\": \"My Reply\"\n}",
4578+
"options": {
4579+
"raw": {
4580+
"language": "json"
4581+
}
4582+
}
4583+
},
4584+
"url": {
4585+
"raw": "{{host}}/messages/see/message_me",
4586+
"host": [
4587+
"{{host}}"
4588+
],
4589+
"path": [
4590+
"messages",
4591+
"see",
4592+
"message_me"
4593+
]
4594+
}
4595+
},
4596+
"response": []
4597+
},
4598+
{
4599+
"name": "Get conversations after seeing messages",
4600+
"event": [
4601+
{
4602+
"listen": "test",
4603+
"script": {
4604+
"id": "960b7ce1-2437-412c-b4dd-f0db3b562a6c",
4605+
"exec": [
4606+
"var response = JSON.parse(responseBody);",
4607+
"",
4608+
"",
4609+
"pm.test(\"Status code is 200\", function () {",
4610+
" pm.response.to.have.status(200);",
4611+
"});",
4612+
"",
4613+
"tests[\"Conversations is empty\"] = response.conversations.length == 1",
4614+
"tests[\"Message is unseen because you received the message\"] = response.conversations[0].is_unseen == false",
4615+
"tests[\"Message content is correct\"] = response.conversations[0].last_message_content == \"My Reply\"",
4616+
"tests[\"With user is correct\"] = response.conversations[0].with_user.username == \"message_me\""
4617+
],
4618+
"type": "text/javascript"
4619+
}
4620+
}
4621+
],
4622+
"request": {
4623+
"method": "GET",
4624+
"header": [],
4625+
"url": {
4626+
"raw": "{{host}}/conversations",
4627+
"host": [
4628+
"{{host}}"
4629+
],
4630+
"path": [
4631+
"conversations"
4632+
]
4633+
}
4634+
},
4635+
"response": []
44994636
}
45004637
],
45014638
"protocolProfileBehavior": {}
@@ -4658,92 +4795,92 @@
46584795
],
46594796
"variable": [
46604797
{
4661-
"id": "0d719212-693f-412b-8d0f-2f8b4d2449b7",
4798+
"id": "51a87d51-b3a6-4cde-9b11-1fe5ad7be7af",
46624799
"key": "host",
46634800
"value": "http://127.0.0.1:5000"
46644801
},
46654802
{
4666-
"id": "ace376bf-356d-480f-ac9c-9ec36db37847",
4803+
"id": "7cbb58d1-cad3-4e00-915f-53a6c467d991",
46674804
"key": "user_id",
46684805
"value": ""
46694806
},
46704807
{
4671-
"id": "ffa52d7f-f0b6-41fd-b9ec-d389df575d24",
4808+
"id": "693836fa-3848-4780-81c7-ad60a40700ae",
46724809
"key": "user_email",
46734810
"value": "foo@example.org"
46744811
},
46754812
{
4676-
"id": "979d1a03-d820-4611-8a78-5f8246321dd6",
4813+
"id": "02053d62-a0a9-40bb-8e6f-43d86eb1fa17",
46774814
"key": "user_username",
46784815
"value": "foo"
46794816
},
46804817
{
4681-
"id": "fde9178c-cfe4-45a0-b10d-cdaa482c6b04",
4818+
"id": "760554e4-b902-431a-b29b-03679009434c",
46824819
"key": "user_password",
46834820
"value": "admin"
46844821
},
46854822
{
4686-
"id": "b7bac1d5-3f76-498f-a26c-2f70e66dd3ef",
4823+
"id": "8d73261c-6557-4939-9718-c5f3ed186ea8",
46874824
"key": "user_firstname",
46884825
"value": "Foo"
46894826
},
46904827
{
4691-
"id": "7e1b40c3-5dd7-48e0-8963-cf1e82182f3e",
4828+
"id": "f7fa880d-6264-44f7-a8ce-c470ff077a83",
46924829
"key": "user_lastname",
46934830
"value": "Bar"
46944831
},
46954832
{
4696-
"id": "166c22c4-85f5-4ebc-b107-65c43015a6bf",
4833+
"id": "28f7acd5-c6b0-4e82-a04c-17371197787b",
46974834
"key": "debug_token",
46984835
"value": "xX69jules69Xx"
46994836
},
47004837
{
4701-
"id": "dd075e81-7f88-447e-8ce5-a49cc4343c9c",
4838+
"id": "ad555769-0803-4b30-a7a2-fdb9d582fd4d",
47024839
"key": "user_access_token",
47034840
"value": ""
47044841
},
47054842
{
4706-
"id": "8c67aae4-989e-4881-93d5-04ce840ca391",
4843+
"id": "bd3194a6-e6b3-4f1d-a3f5-bf41341dc093",
47074844
"key": "user_refresh_token",
47084845
"value": ""
47094846
},
47104847
{
4711-
"id": "9e1d6d72-eec2-4c9a-bfe7-a7fb747eb16f",
4848+
"id": "f35b0ce7-b46a-41ac-8c79-efa76178786e",
47124849
"key": "expired_token",
47134850
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU"
47144851
},
47154852
{
4716-
"id": "15bc3df5-1ecb-451c-b6b1-3793752ac5ea",
4853+
"id": "e22e2d2f-a517-4b9b-890f-9393c8656aed",
47174854
"key": "user_orientation",
47184855
"value": "heterosexual"
47194856
},
47204857
{
4721-
"id": "d5bdf7cd-be04-4f7d-9180-8bcc7e2f072b",
4858+
"id": "2a8b6700-24d1-4ca6-b29c-d022b8a5fb8c",
47224859
"key": "user_bio",
47234860
"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."
47244861
},
47254862
{
4726-
"id": "1f55fa55-81a8-407e-a81b-848d6ed0a59a",
4863+
"id": "597a56c2-2530-4900-ae36-b3e10175d936",
47274864
"key": "user_gender",
47284865
"value": "male"
47294866
},
47304867
{
4731-
"id": "4a078274-7c01-496a-8369-b6721c03bd5a",
4868+
"id": "3c09e8cb-9e4a-4274-90fe-354196c4c64a",
47324869
"key": "user_birthdate",
47334870
"value": "06/04/1998"
47344871
},
47354872
{
4736-
"id": "3997d428-1157-4b69-9765-6a86f3d07457",
4873+
"id": "73a843d0-a43e-4829-92b4-099a8f86ae74",
47374874
"key": "user_lat",
47384875
"value": "44.8404"
47394876
},
47404877
{
4741-
"id": "30e174fa-6eea-4fde-b9bd-919d6d50f2b3",
4878+
"id": "3ad8f109-e36f-43dd-9f60-077a4fbe06b8",
47424879
"key": "user_lng",
47434880
"value": "-0.5805"
47444881
},
47454882
{
4746-
"id": "ae6d5c69-4bb7-4bf4-9bc8-52999dc780f7",
4883+
"id": "0a23376b-a2a7-4d5c-8cd4-ba2dcbdfbe58",
47474884
"key": "user_ip",
47484885
"value": "77.205.46.181"
47494886
}

backend/PyMatcha/routes/api/messages.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@
3636

3737
"""
3838
test get all messages
39-
test when is_unseen is true
4039
test more than one conv
41-
test see message
4240
test like message
43-
test unseen conversations
4441
"""
4542

4643

@@ -100,11 +97,13 @@ def see_conversation_messages(with_uid):
10097
try:
10198
with_user = get_user(with_uid)
10299
except NotFoundError:
103-
raise NotFoundError("With user {} not found", "Try again")
104-
for message in Message.get_multis(from_id=with_user.id, to_id=current_user.id, is_seen=False):
105-
message.is_seen = True
106-
message.save()
107-
return Success("Messages marked as seen")
100+
raise NotFoundError(f"With user {with_uid} not found", "Try again")
101+
unseen_messages = Message.get_multis(from_id=with_user.id, to_id=current_user.id, is_seen=False)
102+
if unseen_messages:
103+
for message in unseen_messages:
104+
message.is_seen = True
105+
message.save()
106+
return Success("Messages marked as seen.")
108107

109108

110109
@messages_bp.route("/messages/like/<message_id>", methods=["POSt"])

0 commit comments

Comments
 (0)