package system

import (
	"context"
	"testing"

	bizsystem "kra/internal/biz/system"
)

func TestListLoginsCanFilterFailedStatus(t *testing.T) {
	data := newTransactionTestData(t)
	ctx := context.Background()
	if err := data.gormDB.WithContext(ctx).Create(&[]loginLogPO{
		{Username: "ok", Status: true},
		{Username: "failed", Status: false},
	}).Error; err != nil {
		t.Fatal(err)
	}
	status := false
	items, total, err := (&auditQueryRepo{data: data}).ListLogins(ctx, 1, 20, &bizsystem.LoginLogFilter{Status: &status})
	if err != nil {
		t.Fatal(err)
	}
	if total != 1 || len(items) != 1 || items[0].Status {
		t.Fatalf("failed login filter = total %d items %#v", total, items)
	}
}
