from graphql_relay import from_global_id

from core.tests.base_test import SkillboxTestCase
from core.tests.helpers import GQLResult

class GQLRoom:
    def __init__(self, room_data):
        self.id = room_data.get('id')
        self.slug = room_data.get('slug')
        self.title = room_data.get('title')
        self.entry_count = room_data.get('entryCount')
        self.appearance = room_data.get('appearance')
        self.description = room_data.get('description')
        self.school_class = room_data.get('schoolClass')

class AddRoomResult:
    def __init__(self, result: GQLResult):
        self.room = GQLRoom(result.data.get('addRoom').get('room'))
#         id
#       slug
#       title
#       entryCount
#       appearance
#       description
#       schoolClass {
#         id
#         name
#       }

class NewRoomMutationTestCase(SkillboxTestCase):
    def setUp(self) -> None:
        self.createDefault()

    def test_create_new_room(self):
        mutation = """
mutation AddRoom($input: AddRoomInput!){
  addRoom(input: $input) {
    room {
      id
      slug
      title
      entryCount
      appearance
      description
      schoolClass {
        id
        name
      }
    }
  }
}
"""
        title = 'some title'
        appearance='blue'
        res = self.get_client().execute(mutation, variables={
            'input': {
                'room': {
                    'title': title,
                    # description
                    'appearance': appearance
                }
            }
        })
        result = GQLResult(res)
        self.assertIsNone(result.errors)
        room = GQLRoom(result.data.get('addRoom').get('room'))
        self.assertEqual(room.title, title)
        self.assertEqual(room.appearance, appearance)
        self.assertIsNone(room.description)
        self.assertEqual(int(from_global_id(room.school_class.get('id'))[1]), self.teacher.selected_class.id)


