import unittest
import manage_sys_paths
import json

from messaging.MessageHandler import MessageHandler
from database.entities.transaction import Transaction

class DummyMongoRepo:
    '''Dummy class to be used for testing the MessageHandler'''
    last_trace = None
    def insert_trace(self, trace):
        self.last_trace = trace

    def add_transaction(self, transaction: Transaction):
        self.last_transaction = transaction

from messaging.DummyMessageManager import DummyMessageManager as DummyMessageSender
from messaging.rest_fetcher import RestFetcher

class Test_MessageHandler(unittest.TestCase):
    handler = None
    repo = None
    msg_sender = None
    rest_fetcher = None

    def setUp(self):
        self.repo = DummyMongoRepo()
        self.msg_sender = DummyMessageSender.get_instance()
        self.rest_fetcher = RestFetcher()
        self.handler = MessageHandler(self.repo, self.msg_sender, self.rest_fetcher)

    def _get_order_message(self) -> str:
        message_values = \
        {
          'type': 'blockchain-transaction',
          'content': 
            {
                "ApplicationType": "debug",
                "docType": "order",
                "orderId": 1,
                "pizza": 1,
                "price": 12.0,
                "restaurant": 1,
            }
        }
        return json.dumps(message_values)

    def _get_pizza_message(self) -> str:
        message_values = \
        {
          "type": "blockchain-transaction",
          "content": 
            {
                "ApplicationType": "debug",
                "docType": "pizza",
                "id": 1,
                "name": "Diavolo",
                "dough": {
                    "type": "wheat",
                    "spinach": False
                },
                "toppings": [
                    {
                        "name": "cheese",
                        "price": 0.50,
                    },
                    {
                        "name": "peppers",
                        "price": 1.00,
                    },
                    {
                        "name": "chilli-oil",
                        "price": 0.1,
                    }
                ],
            }
        }
        return json.dumps(message_values)

if __name__ == '__main__':
    unittest.main()