This commit is contained in:
KoalaSat
2024-06-21 11:09:18 +02:00
parent a9e411d359
commit 88467b2b93
3 changed files with 221 additions and 0 deletions

View File

@ -284,6 +284,30 @@ paths:
type: string
description: Reason for the failure
description: ''
/api/notifications/:
get:
operationId: notifications_list
description: Get a list of notifications sent to the robot.
summary: Get robot notifications
parameters:
- in: query
name: created_at
schema:
type: string
description: Shows notifications created AFTER this date.
tags:
- notifications
security:
- tokenAuth: []
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Notification'
description: ''
/api/order/:
get:
operationId: order_retrieve
@ -1262,6 +1286,19 @@ components:
* `success` - success
* `error` - error
* `info` - info
Notification:
type: object
properties:
title:
type: string
description:
type: string
order_id:
type: integer
readOnly: true
required:
- order_id
- title
NullEnum:
enum:
- null

View File

@ -239,6 +239,16 @@ class TradeTest(BaseAPITestCase):
self.assertIsNone(data["taker"], "New order's taker is not null")
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
0,
"There is only one notification",
)
def test_make_order_on_blocked_country(self):
"""
Test the creation of an F2F order on a geoblocked location
@ -347,6 +357,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
1,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_pause_unpause_order(self):
"""
Tests pausing and unpausing a public order
@ -369,6 +390,17 @@ class TradeTest(BaseAPITestCase):
self.assertResponse(trade.response)
self.assertEqual(data["status_message"], Order.Status(Order.Status.PUB).label)
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
2,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Cancel order to avoid leaving pending HTLCs after a successful test
trade.cancel_order()
@ -415,6 +447,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
2,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_make_and_lock_contract(self):
"""
Tests a trade from order creation to taker bond locked.
@ -437,6 +480,17 @@ class TradeTest(BaseAPITestCase):
self.assertTrue(data["taker_locked"])
self.assertFalse(data["escrow_locked"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
2,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Maker GET
trade.get_order(trade.maker_index)
data = trade.response.json()
@ -457,6 +511,17 @@ class TradeTest(BaseAPITestCase):
self.assertTrue(data["taker_locked"])
self.assertFalse(data["escrow_locked"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
2,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Maker cancels order to avoid leaving pending HTLCs after a successful test
trade.cancel_order()
@ -483,6 +548,17 @@ class TradeTest(BaseAPITestCase):
self.assertTrue(data["taker_locked"])
self.assertTrue(data["escrow_locked"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
3,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Cancel order to avoid leaving pending HTLCs after a successful test
trade.cancel_order(trade.taker_index)
@ -506,6 +582,17 @@ class TradeTest(BaseAPITestCase):
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
self.assertFalse(data["is_fiat_sent"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
4,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Cancel order to avoid leaving pending HTLCs after a successful test
trade.cancel_order(trade.maker_index)
trade.cancel_order(trade.taker_index)
@ -532,6 +619,17 @@ class TradeTest(BaseAPITestCase):
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
self.assertFalse(data["is_fiat_sent"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
5,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Cancel order to avoid leaving pending HTLCs after a successful test
trade.cancel_order(trade.maker_index)
trade.cancel_order(trade.taker_index)
@ -556,6 +654,17 @@ class TradeTest(BaseAPITestCase):
self.assertEqual(data["status_message"], Order.Status(Order.Status.FSE).label)
self.assertTrue(data["is_fiat_sent"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
6,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Cancel order to avoid leaving pending HTLCs after a successful test
trade.undo_confirm_sent(trade.maker_index)
data = trade.response.json()
@ -595,6 +704,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
7,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_successful_LN(self):
"""
Tests a trade from order creation until Sats sent to buyer
@ -702,6 +822,17 @@ class TradeTest(BaseAPITestCase):
"This order has been cancelled collaborativelly",
)
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
6,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_created_order_expires(self):
"""
Tests the expiration of a public order
@ -734,6 +865,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
6,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_public_order_expires(self):
"""
Tests the expiration of a public order
@ -767,6 +909,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
6,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_taken_order_expires(self):
"""
Tests the expiration of a public order
@ -802,6 +955,17 @@ class TradeTest(BaseAPITestCase):
self.assert_order_logs(data["id"])
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
6,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
def test_escrow_locked_expires(self):
"""
Tests the expiration of a public order
@ -890,6 +1054,17 @@ class TradeTest(BaseAPITestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {}) # Nothing in the response
trade.get_notifications()
# Checks
self.assertResponse(trade.response)
notifications_data = trade.response.json()
self.assertEqual(
notifications_data.count,
8,
"There is only one notification",
)
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
# Get the two chatroom messages as maker
response = self.client.get(path + params, **maker_headers)
self.assertResponse(response)

View File

@ -111,6 +111,15 @@ class Trade:
headers = self.get_robot_auth(robot_index, first_encounter)
self.response = self.client.get(path + params, **headers)
def get_notifications(self, created_at=0, robot_index=1, first_encounter=False):
"""
Fetch the latest state of the order
"""
path = reverse("notifications")
params = f"?created_at={created_at}"
headers = self.get_robot_auth(robot_index, first_encounter)
self.response = self.client.get(path + params, **headers)
@patch("api.tasks.send_notification.delay", send_notification)
def cancel_order(self, robot_index=1):
path = reverse("order")