package security

import (
	"context"
	"testing"

	"github.com/smartystreets/goconvey/convey"
	"github.com/tidbcloud/account/internel/dao/entity"
)

func deleteAuditLogByID(id uint64) {
	db.Where("id = ?", id).Delete(&entity.AuditLog{})
}

func TestSecurityDao_CreateAuditLog(t *testing.T) {
	d := SecurityDao{}
	ctx := context.TODO()

	convey.Convey("CreateAuditLog", t, func() {
		auditLog, err := d.CreateAuditLog(ctx, db, 1, "someone@pingcap.com", "I'm the content")
		convey.So(err, convey.ShouldBeNil)
		convey.So(auditLog.ID.Uint64(), convey.ShouldBeGreaterThanOrEqualTo, 1)

		// create it again
		auditLog, err = d.CreateAuditLog(ctx, db, 1, "someone@pingcap.com", "I'm the content")
		convey.So(err, convey.ShouldBeNil)
		convey.So(auditLog.ID.Uint64(), convey.ShouldBeGreaterThanOrEqualTo, 2)

		deleteAuditLogByID(auditLog.ID.Uint64())
	})
}
