import pytest
import json
from app import BatchedUpdate

def test_batched_update_creation():
    """Test creating batched update object"""
    batch = BatchedUpdate()

    batch.add('energy', 100)
    batch.add('money', 5000)
    batch.add('hourOfDay', 10)

    result = batch.to_dict()
    assert result['type'] == 'batch_update'
    assert result['updates']['energy'] == 100
    assert result['updates']['money'] == 5000
    assert result['updates']['hourOfDay'] == 10

def test_batched_update_json_serialization():
    """Test that batched updates serialize correctly"""
    batch = BatchedUpdate()
    batch.add('test_field', 'test_value')

    json_str = batch.to_json()
    parsed = json.loads(json_str)

    assert parsed['type'] == 'batch_update'
    assert parsed['updates']['test_field'] == 'test_value'

def test_empty_batch():
    """Test that empty batches return None"""
    batch = BatchedUpdate()
    assert batch.to_dict() is None
