Unit testing #23
| @ -21,9 +21,9 @@ import ( | ||||
| type application struct { | ||||
| 	sequence          uint16 | ||||
| 	logger            *slog.Logger | ||||
| 	websites          *models.WebsiteModel | ||||
| 	users             *models.UserModel | ||||
| 	guestbookComments *models.GuestbookCommentModel | ||||
| 	websites          models.WebsiteModelInterface | ||||
| 	users             models.UserModelInterface | ||||
| 	guestbookComments models.GuestbookCommentModelInterface | ||||
| 	sessionManager    *scs.SessionManager | ||||
| 	formDecoder       *schema.Decoder | ||||
| 	debug             bool | ||||
|  | ||||
| @ -30,7 +30,6 @@ func newTestApplication(t *testing.T) *application { | ||||
| 		logger:            slog.New(slog.NewTextHandler(io.Discard, nil)), | ||||
| 		sessionManager:    sessionManager, | ||||
| 		websites:          &mocks.WebsiteModel{}, | ||||
| 		guestbooks:        &mocks.GuestbookModel{}, | ||||
| 		users:             &mocks.UserModel{}, | ||||
| 		guestbookComments: &mocks.GuestbookCommentModel{}, | ||||
| 		formDecoder:       formDecoder, | ||||
|  | ||||
| @ -1,66 +0,0 @@ | ||||
| package mocks | ||||
| 
 | ||||
| import ( | ||||
| 	"time" | ||||
| 
 | ||||
| 	"git.32bit.cafe/32bitcafe/guestbook/internal/models" | ||||
| ) | ||||
| 
 | ||||
| var mockGuestbook = models.Guestbook{ | ||||
| 	ID:        1, | ||||
| 	ShortId:   1, | ||||
| 	UserId:    1, | ||||
| 	WebsiteId: 1, | ||||
| 	Created:   time.Now(), | ||||
| 	IsActive:  true, | ||||
| 	Settings: models.GuestbookSettings{ | ||||
| 		IsCommentingEnabled:   true, | ||||
| 		IsVisible:             true, | ||||
| 		FilteredWords:         make([]string, 0), | ||||
| 		AllowRemoteHostAccess: true, | ||||
| 	}, | ||||
| } | ||||
| 
 | ||||
| type GuestbookModel struct{} | ||||
| 
 | ||||
| func (m *GuestbookModel) InitializeSettingsMap() error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) Insert(shortId uint64, userId int64, websiteId int64, settings models.GuestbookSettings) (int64, error) { | ||||
| 	return 2, nil | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) Get(shortId uint64) (models.Guestbook, error) { | ||||
| 	switch shortId { | ||||
| 	case 1: | ||||
| 		return mockGuestbook, nil | ||||
| 	default: | ||||
| 		return models.Guestbook{}, models.ErrNoRecord | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) GetAll(userId int64) ([]models.Guestbook, error) { | ||||
| 	switch userId { | ||||
| 	case 1: | ||||
| 		return []models.Guestbook{mockGuestbook}, nil | ||||
| 	default: | ||||
| 		return []models.Guestbook{}, models.ErrNoRecord | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) UpdateGuestbookSettings(guestbookId int64, settings models.GuestbookSettings) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) UpdateSetting(guestbookId int64, setting models.Setting, value string) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) AddFilteredWord(guestbookId int64, word string) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *GuestbookModel) RemoveFilteredWord(guestbookId int64, word string) error { | ||||
| 	return nil | ||||
| } | ||||
| @ -6,6 +6,21 @@ import ( | ||||
| 	"git.32bit.cafe/32bitcafe/guestbook/internal/models" | ||||
| ) | ||||
| 
 | ||||
| var mockGuestbook = models.Guestbook{ | ||||
| 	ID:        1, | ||||
| 	ShortId:   1, | ||||
| 	UserId:    1, | ||||
| 	WebsiteId: 1, | ||||
| 	Created:   time.Now(), | ||||
| 	IsActive:  true, | ||||
| 	Settings: models.GuestbookSettings{ | ||||
| 		IsCommentingEnabled:   true, | ||||
| 		IsVisible:             true, | ||||
| 		FilteredWords:         make([]string, 0), | ||||
| 		AllowRemoteHostAccess: true, | ||||
| 	}, | ||||
| } | ||||
| 
 | ||||
| var mockWebsite = models.Website{ | ||||
| 	ID:         1, | ||||
| 	ShortId:    1, | ||||
| @ -48,3 +63,15 @@ func (m *WebsiteModel) GetById(id int64) (models.Website, error) { | ||||
| func (m *WebsiteModel) GetAll() ([]models.Website, error) { | ||||
| 	return []models.Website{mockWebsite}, nil | ||||
| } | ||||
| 
 | ||||
| func (m *WebsiteModel) InitializeSettingsMap() error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *WebsiteModel) UpdateGuestbookSettings(guestbookId int64, settings models.GuestbookSettings) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (m *WebsiteModel) UpdateSetting(guestbookId int64, setting models.Setting, value string) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| @ -43,7 +43,6 @@ type UserModelInterface interface { | ||||
| 	GetAll() ([]User, error) | ||||
| 	Authenticate(email, password string) (int64, error) | ||||
| 	Exists(id int64) (bool, error) | ||||
| 	GetSettings(userId int64) (UserSettings, error) | ||||
| 	UpdateUserSettings(userId int64, settings UserSettings) error | ||||
| 	UpdateSetting(userId int64, setting Setting, value string) error | ||||
| } | ||||
|  | ||||
| @ -93,9 +93,11 @@ func (m *WebsiteModel) InitializeSettingsMap() error { | ||||
| type WebsiteModelInterface interface { | ||||
| 	Insert(shortId uint64, userId int64, siteName, siteUrl, authorName string) (int64, error) | ||||
| 	Get(shortId uint64) (Website, error) | ||||
| 	GetById(id int64) (Website, error) | ||||
| 	GetAllUser(userId int64) ([]Website, error) | ||||
| 	GetAll() ([]Website, error) | ||||
| 	InitializeSettingsMap() error | ||||
| 	UpdateGuestbookSettings(guestbookId int64, settings GuestbookSettings) error | ||||
| 	UpdateSetting(guestbookId int64, setting Setting, value string) error | ||||
| } | ||||
| 
 | ||||
| func (m *WebsiteModel) Insert(shortId uint64, userId int64, siteName, siteUrl, authorName string) (int64, error) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user