package queries_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
	m "github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/db"
	"github.com/fiskerinc/cloud-services/pkg/db/queries"
	"github.com/fiskerinc/cloud-services/pkg/testhelper"
)

func TestIssueImageIntegration(t *testing.T) {
	t.Skip()
	query := setupIssueImages(t)
	testIssueImagesInsert(t, query)
	testIssueImagesSearch(t, query)
}
func setupIssueImages(t *testing.T) queries.IssueImages {
	instance := queries.IssueImages{}
	conn = instance.GetDBConn()
	conn.AddQueryHook(db.SQLLogger{})

	client := instance.GetClient()
	client.InitSchema([]interface{}{
		(*common.Issue)(nil),
	})

	return instance
}

func testIssueImagesInsert(t *testing.T, query queries.IssueImages) {

	issueImage := []m.IssueImage{
		{
			Image:   []byte{72, 101, 108, 108, 111, 49},
			IssueID: 1,
		},
		{
			Image:   []byte{72, 101, 108, 108, 111, 111},
			IssueID: 1,
		},
	}

	res, err := query.Insert(&issueImage)
	if err != nil {
		t.Errorf(testhelper.TestErrorTemplate, "IssueImages update", "No error", err)
	}

	if res.RowsAffected() != 2 {
		t.Errorf(testhelper.TestErrorTemplate, "IssueImages insert RowsAffected", 1, res.RowsAffected())
	}
}

func testIssueImagesSearch(t *testing.T, query queries.IssueImages) {

	_, err := query.SearchByIssueID("22")
	if err != nil {
		t.Errorf(testhelper.TestErrorTemplate, "Issue Image Search", "No error", err)
	}

}
