<?php

use App\Models\Classification;
use App\Models\SubClassification;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('sub classification can be created using factory', function () {
    $sub = SubClassification::factory()->create(['name' => 'Sub Test']);

    expect($sub->name)->toBe('Sub Test');
    expect($sub->classification)->toBeInstanceOf(Classification::class);
});

test('sub classification belongs to a classification', function () {
    $parent = Classification::factory()->create();
    $sub = SubClassification::factory()->create(['classification_id' => $parent->id]);

    expect($sub->classification->id)->toBe($parent->id);
});

test('classification has many sub classifications relationship works', function () {
    $parent = Classification::factory()->create();
    SubClassification::factory()->count(3)->create(['classification_id' => $parent->id]);

    expect($parent->subClassifications)->toHaveCount(3);
});
