<commit_before>package usecase_test

import (
	"testing"

	"github.com/arielizuardi/ezra/facilitator"
	mocksFacilitatorRepository "github.com/arielizuardi/ezra/facilitator/repository/mocks"
	"github.com/arielizuardi/ezra/feedback"
	"github.com/arielizuardi/ezra/feedback/report/usecase"
	mocksFeedbackRepository "github.com/arielizuardi/ezra/feedback/repository/mocks"
	"github.com/arielizuardi/ezra/presenter"
	mocksPresenterRepository "github.com/arielizuardi/ezra/presenter/repository/mocks"
	"github.com/stretchr/testify/assert"
)

func TestGeneratePresenterReport(t *testing.T) {
	presenterID := int64(1)
	session := int64(1)
	batch := int64(1)
	year := int64(2017)

	p := new(presenter.Presenter)
	pr := new(mocksPresenterRepository.Repository)
	pr.On(`Get`, presenterID).Return(p, nil)

	feedbacks := []*feedback.PresenterFeedback{}
	fr := new(mocksFeedbackRepository.Repository)
	fr.On(`FetchPresenterFeedbacks`, presenterID, session, batch, year).Return(feedbacks, nil)

	fcr := new(mocksFacilitatorRepository.Repository)

	u := usecase.NewReportUsecase(pr, fcr, fr)

	report, err := u.GeneratePresenterReport(presenterID, session, batch, year)
	assert.NoError(t, err)
	assert.NotNil(t, report)

	pr.AssertCalled(t, `Get`, presenterID)
	fr.AssertCalled(t, `FetchPresenterFeedbacks`, presenterID, session, batch, year)
}

func TestGenerateFacilitatorReport(t *testing.T) {
	facilitatorID := int64(1)
	batch := int64(1)
	year := int64(2017)

	f := new(facilitator.Facilitator)
	fcr := new(mocksFacilitatorRepository.Repository)
	fcr.On(`Get`, facilitatorID).Return(f, nil)

	feedbacks := []*feedback.FacilitatorFeedback{}
	fbr := new(mocksFeedbackRepository.Repository)
	fbr.On(`FetchFacilitatorFeedbacks`, facilitatorID, batch, year).Return(feedbacks, nil)

	pr := new(mocksPresenterRepository.Repository)

	u := usecase.NewReportUsecase(pr, fcr, fbr)

	report, err := u.GenerateFacilitatorReport(facilitatorID, batch, year)
	assert.NoError(t, err)
	assert.NotNil(t, report)

	fcr.AssertCalled(t, `Get`, facilitatorID)
	fbr.AssertCalled(t, `FetchFacilitatorFeedbacks`, facilitatorID, batch, year)
}<commit_msg>Update usecase test<commit_after>package usecase_test

import (
	"testing"

	"github.com/arielizuardi/ezra/facilitator"
	mocksFacilitatorRepository "github.com/arielizuardi/ezra/facilitator/repository/mocks"
	"github.com/arielizuardi/ezra/feedback"
	"github.com/arielizuardi/ezra/feedback/report/usecase"
	mocksFeedbackRepository "github.com/arielizuardi/ezra/feedback/repository/mocks"
	"github.com/arielizuardi/ezra/presenter"
	mocksPresenterRepository "github.com/arielizuardi/ezra/presenter/repository/mocks"
	"github.com/stretchr/testify/assert"
)

func TestGeneratePresenterReport(t *testing.T) {
	presenterID := int64(1)
	session := int64(1)
	batch := int64(1)
	year := int64(2017)

	p := new(presenter.Presenter)
	pr := new(mocksPresenterRepository.Repository)
	pr.On(`Get`, presenterID).Return(p, nil)

	feedbacks := []*feedback.PresenterFeedback{}
	fr := new(mocksFeedbackRepository.Repository)
	fr.On(`FetchPresenterFeedbacks`, presenterID, session, batch, year).Return(feedbacks, nil)

	fcr := new(mocksFacilitatorRepository.Repository)

	u := usecase.NewReportUsecase(pr, fcr, fr)

	report, err := u.GeneratePresenterReport(presenterID, session, batch, year)
	assert.NoError(t, err)
	assert.NotNil(t, report)

	pr.AssertCalled(t, `Get`, presenterID)
	fr.AssertCalled(t, `FetchPresenterFeedbacks`, presenterID, session, batch, year)
}

func TestGeneratePresenterReportNonExistsPresenter(t *testing.T) {
	presenterID := int64(1)
	session := int64(1)
	batch := int64(1)
	year := int64(2017)

	pr := new(mocksPresenterRepository.Repository)
	pr.On(`Get`, presenterID).Return(nil, nil)

	fr := new(mocksFeedbackRepository.Repository)
	fcr := new(mocksFacilitatorRepository.Repository)
	u := usecase.NewReportUsecase(pr, fcr, fr)

	report, err := u.GeneratePresenterReport(presenterID, session, batch, year)
	assert.EqualError(t, presenter.ErrPresenterNotFound, err.Error())
	assert.Nil(t, report)

	pr.AssertCalled(t, `Get`, presenterID)
	fr.AssertNotCalled(t, `FetchPresenterFeedbacks`, presenterID, session, batch, year)
}

func TestGenerateFacilitatorReport(t *testing.T) {
	facilitatorID := int64(1)
	batch := int64(1)
	year := int64(2017)

	f := new(facilitator.Facilitator)
	fcr := new(mocksFacilitatorRepository.Repository)
	fcr.On(`Get`, facilitatorID).Return(f, nil)

	feedbacks := []*feedback.FacilitatorFeedback{}
	fbr := new(mocksFeedbackRepository.Repository)
	fbr.On(`FetchFacilitatorFeedbacks`, facilitatorID, batch, year).Return(feedbacks, nil)

	pr := new(mocksPresenterRepository.Repository)

	u := usecase.NewReportUsecase(pr, fcr, fbr)

	report, err := u.GenerateFacilitatorReport(facilitatorID, batch, year)
	assert.NoError(t, err)
	assert.NotNil(t, report)

	fcr.AssertCalled(t, `Get`, facilitatorID)
	fbr.AssertCalled(t, `FetchFacilitatorFeedbacks`, facilitatorID, batch, year)
}

func TestGenerateFacilitatorReportNonExistsFacilitator(t *testing.T) {
	facilitatorID := int64(1)
	batch := int64(1)
	year := int64(2017)

	fcr := new(mocksFacilitatorRepository.Repository)
	fcr.On(`Get`, facilitatorID).Return(nil, nil)

	fbr := new(mocksFeedbackRepository.Repository)
	pr := new(mocksPresenterRepository.Repository)

	u := usecase.NewReportUsecase(pr, fcr, fbr)

	report, err := u.GenerateFacilitatorReport(facilitatorID, batch, year)
	assert.EqualError(t, facilitator.ErrFacilitatorNotFound, err.Error())
	assert.Nil(t, report)

	fcr.AssertCalled(t, `Get`, facilitatorID)
	fbr.AssertNotCalled(t, `FetchFacilitatorFeedbacks`, facilitatorID, batch, year)
}
{'fraction_non_alphanumeric': 0.13349991076209175, 'fraction_numerical': 0.01445654113867571, 'mean_word_length': 6.805013927576602, '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': '4110293', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2038, 'n_words': 318}