<commit_before>package dashboard

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/suite"
)

type DashboardServiceTestSuite struct {
	suite.Suite
	MigratorInstance  *MigratorMock
	DbManagerInstance *DatabaseManagerMock
}

func (s *DashboardServiceTestSuite) SetupSuite() {
}

func (s *DashboardServiceTestSuite) SetupTest() {
	s.MigratorInstance = new(MigratorMock)
	s.DbManagerInstance = new(DatabaseManagerMock)
}

func TestDashboardServiceTestSuite(t *testing.T) {
	suite.Run(t, new(DashboardServiceTestSuite))
}

func (s *DashboardServiceTestSuite) TestGetPagesReturnPagesArray() {
	var pages = []Page{
		Page{
			Id:      1,
			Title:   "page1",
			Visible: true,
			Widgets: []Widget{
				Widget{Id: "widget_1", Url: "http://example.com:8080/", Width: 450, Height: 350},
			},
		},
		Page{
			Id:      2,
			Title:   "page2",
			Visible: true,
			Widgets: []Widget{
				Widget{Id: "widget_1", Url: "http://example.com:8081/", Width: 250, Height: 150},
				Widget{Id: "widget_2", Url: "http://example.com:8081/", Width: 250, Height: 150},
			},
		},
	}

	s.DbManagerInstance.On("GetPages").Return(pages, nil)

	var service = NewDashboardService(s.MigratorInstance, s.DbManagerInstance)
	pages, err := service.GetPages()
	s.DbManagerInstance.AssertNumberOfCalls(s.T(), "GetPages", 1)
	assert.NotNil(s.T(), pages)
	assert.Nil(s.T(), err)
}

func (s *DashboardServiceTestSuite) TearDownTest() {
	s.MigratorInstance = nil
	s.DbManagerInstance = nil
}

func (suite *DashboardServiceTestSuite) TearDownSuite() {
}
<commit_msg>SM-21 #time 20m Added test for insert widget success, fail<commit_after>package dashboard

import (
	"errors"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/suite"
)

type DashboardServiceTestSuite struct {
	suite.Suite
	MigratorInstance  *MigratorMock
	DbManagerInstance *DatabaseManagerMock
}

func (s *DashboardServiceTestSuite) SetupSuite() {
}

func (s *DashboardServiceTestSuite) SetupTest() {
	s.MigratorInstance = new(MigratorMock)
	s.DbManagerInstance = new(DatabaseManagerMock)
}

func TestDashboardServiceTestSuite(t *testing.T) {
	suite.Run(t, new(DashboardServiceTestSuite))
}

func (s *DashboardServiceTestSuite) TestGetPagesReturnPagesArray() {
	var pages = []Page{
		Page{
			Id:      1,
			Title:   "page1",
			Visible: true,
			Widgets: []Widget{
				Widget{Id: "widget_1", Url: "http://example.com:8080/", Width: 450, Height: 350},
			},
		},
		Page{
			Id:      2,
			Title:   "page2",
			Visible: true,
			Widgets: []Widget{
				Widget{Id: "widget_1", Url: "http://example.com:8081/", Width: 250, Height: 150},
				Widget{Id: "widget_2", Url: "http://example.com:8081/", Width: 250, Height: 150},
			},
		},
	}

	s.DbManagerInstance.On("GetPages").Return(pages, nil)

	var service = NewDashboardService(s.MigratorInstance, s.DbManagerInstance)
	pages, err := service.GetPages()
	s.DbManagerInstance.AssertNumberOfCalls(s.T(), "GetPages", 1)
	assert.NotNil(s.T(), pages)
	assert.Nil(s.T(), err)
}

func (s *DashboardServiceTestSuite) TestRegisterWidgetSuccess() {
	var expectedResponse = RegisterResponse{Success: true}
	var widget = Widget{
		Id:     "widget_1",
		Url:    "http://example.com:8081/",
		Width:  250,
		Height: 150,
	}

	s.DbManagerInstance.On("InsertOrUpdateWidget", &widget).Return(int64(1), nil)
	var service = NewDashboardService(s.MigratorInstance, s.DbManagerInstance)

	actualResponse, err := service.Register(widget)

	s.DbManagerInstance.AssertNumberOfCalls(s.T(), "InsertOrUpdateWidget", 1)
	assert.Equal(s.T(), expectedResponse, actualResponse)
	assert.Nil(s.T(), err)
}

func (s *DashboardServiceTestSuite) TestRegisterWidgetFail() {
	var expectedResponse = RegisterResponse{Success: false}
	var expectedError = errors.New("Some error")
	var widget = Widget{
		Id:     "widget_2",
		Url:    "http://example.com:8000/",
		Width:  250,
		Height: 150,
	}

	s.DbManagerInstance.On("InsertOrUpdateWidget", &widget).Return(int64(0), expectedError)
	var service = NewDashboardService(s.MigratorInstance, s.DbManagerInstance)

	actualResponse, actualError := service.Register(widget)

	s.DbManagerInstance.AssertNumberOfCalls(s.T(), "InsertOrUpdateWidget", 1)
	assert.Equal(s.T(), expectedResponse, actualResponse)
	assert.Equal(s.T(), expectedError, actualError)
}

func (s *DashboardServiceTestSuite) TearDownTest() {
	s.MigratorInstance = nil
	s.DbManagerInstance = nil
}

func (suite *DashboardServiceTestSuite) TearDownSuite() {
}

{'fraction_non_alphanumeric': 0.1426016987036209, 'fraction_numerical': 0.024586499776486366, 'mean_word_length': 5.0228802153432035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '630463', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1587, 'n_words': 305}