package system

import (
	"context"
	"testing"
)

func TestVersionRepositoryPreservesNullableFields(t *testing.T) {
	data := newTransactionTestData(t)
	ctx := context.Background()
	if err := data.gormDB.WithContext(ctx).Exec(
		"INSERT INTO sys_versions (created_at, updated_at, version_name, version_code, description, version_data) VALUES (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, NULL, NULL, NULL, NULL)",
	).Error; err != nil {
		t.Fatal(err)
	}

	value, err := (&versionRepo{data: data}).FindVersion(ctx, 1)
	if err != nil {
		t.Fatal(err)
	}
	if value.Name != nil || value.Code != nil || value.Description != nil || value.Data != nil {
		t.Fatalf("nullable version fields = %#v/%#v/%#v/%#v, want nil", value.Name, value.Code, value.Description, value.Data)
	}
}
