import 'package:flutter_test/flutter_test.dart'; import 'package:pokeguess/domain/entities/pokemon.dart'; import 'package:pokeguess/data/dto/pokemon_dto.dart'; void main() { group('PokemonDto.fromTyradexJson', () { test('parse un Pokémon complet avec deux types', () { final json = { 'pokedex_id': 6, 'name': {'fr': 'Dracaufeu', 'en': 'Charizard'}, 'types': [ {'name': 'Feu'}, {'name': 'Vol'}, ], 'stats': {'hp': 78, 'atk': 84, 'def': 78, 'vit': 100}, 'category': 'Pokémon Flamme', }; final p = PokemonDto.fromTyradexJson(json); expect(p.id, 6); expect(p.name, 'Dracaufeu'); expect(p.type1, PokemonType.fire); expect(p.type2, PokemonType.flying); expect(p.hp, 78); expect(p.spd, 100); expect(p.description, 'Pokémon Flamme'); }); test('utilise fallbackId quand pokedex_id absent', () { final json = { 'name': {'fr': 'Bulbizarre'}, 'types': [{'name': 'Plante'}], 'stats': {'hp': 45, 'atk': 49, 'def': 49, 'vit': 45}, 'category': 'Pokémon Graine', }; final p = PokemonDto.fromTyradexJson(json, fallbackId: 1); expect(p.id, 1); expect(p.type2, isNull); expect(p.type1, PokemonType.grass); }); test('type inconnu mappé sur PokemonType.unknown', () { final json = { 'pokedex_id': 999, 'name': {'fr': 'Test'}, 'types': [{'name': 'TypeInexistant'}], 'stats': {'hp': 1, 'atk': 1, 'def': 1, 'vit': 1}, }; final p = PokemonDto.fromTyradexJson(json); expect(p.type1, PokemonType.unknown); expect(p.description, isNull); }); }); group('PokemonDto round-trip DB', () { test('toDb puis fromDb reconstruit le Pokémon', () { const original = Pokemon( name: 'pikachu', id: 25, type1: PokemonType.electric, type2: null, hp: 35, atk: 55, def: 40, spd: 90, description: 'Souris', isCaught: true, isSeen: true, ); final row = PokemonDto.toDb(original); expect(row['type1'], 'electric'); expect(row['type2'], isNull); expect(row['isCaught'], 1); final restored = PokemonDto.fromDb(row); expect(restored.name, 'pikachu'); expect(restored.id, 25); expect(restored.type1, PokemonType.electric); expect(restored.type2, isNull); expect(restored.isCaught, true); expect(restored.isSeen, true); }); }); }