Unit testing #23
| @ -21,9 +21,9 @@ import ( | |||||||
| type application struct { | type application struct { | ||||||
| 	sequence          uint16 | 	sequence          uint16 | ||||||
| 	logger            *slog.Logger | 	logger            *slog.Logger | ||||||
| 	websites          *models.WebsiteModel | 	websites          models.WebsiteModelInterface | ||||||
| 	users             *models.UserModel | 	users             models.UserModelInterface | ||||||
| 	guestbookComments *models.GuestbookCommentModel | 	guestbookComments models.GuestbookCommentModelInterface | ||||||
| 	sessionManager    *scs.SessionManager | 	sessionManager    *scs.SessionManager | ||||||
| 	formDecoder       *schema.Decoder | 	formDecoder       *schema.Decoder | ||||||
| 	debug             bool | 	debug             bool | ||||||
|  | |||||||
| @ -30,7 +30,6 @@ func newTestApplication(t *testing.T) *application { | |||||||
| 		logger:            slog.New(slog.NewTextHandler(io.Discard, nil)), | 		logger:            slog.New(slog.NewTextHandler(io.Discard, nil)), | ||||||
| 		sessionManager:    sessionManager, | 		sessionManager:    sessionManager, | ||||||
| 		websites:          &mocks.WebsiteModel{}, | 		websites:          &mocks.WebsiteModel{}, | ||||||
| 		guestbooks:        &mocks.GuestbookModel{}, |  | ||||||
| 		users:             &mocks.UserModel{}, | 		users:             &mocks.UserModel{}, | ||||||
| 		guestbookComments: &mocks.GuestbookCommentModel{}, | 		guestbookComments: &mocks.GuestbookCommentModel{}, | ||||||
| 		formDecoder:       formDecoder, | 		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" | 	"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{ | var mockWebsite = models.Website{ | ||||||
| 	ID:         1, | 	ID:         1, | ||||||
| 	ShortId:    1, | 	ShortId:    1, | ||||||
| @ -48,3 +63,15 @@ func (m *WebsiteModel) GetById(id int64) (models.Website, error) { | |||||||
| func (m *WebsiteModel) GetAll() ([]models.Website, error) { | func (m *WebsiteModel) GetAll() ([]models.Website, error) { | ||||||
| 	return []models.Website{mockWebsite}, nil | 	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) | 	GetAll() ([]User, error) | ||||||
| 	Authenticate(email, password string) (int64, error) | 	Authenticate(email, password string) (int64, error) | ||||||
| 	Exists(id int64) (bool, error) | 	Exists(id int64) (bool, error) | ||||||
| 	GetSettings(userId int64) (UserSettings, error) |  | ||||||
| 	UpdateUserSettings(userId int64, settings UserSettings) error | 	UpdateUserSettings(userId int64, settings UserSettings) error | ||||||
| 	UpdateSetting(userId int64, setting Setting, value string) error | 	UpdateSetting(userId int64, setting Setting, value string) error | ||||||
| } | } | ||||||
|  | |||||||
| @ -93,9 +93,11 @@ func (m *WebsiteModel) InitializeSettingsMap() error { | |||||||
| type WebsiteModelInterface interface { | type WebsiteModelInterface interface { | ||||||
| 	Insert(shortId uint64, userId int64, siteName, siteUrl, authorName string) (int64, error) | 	Insert(shortId uint64, userId int64, siteName, siteUrl, authorName string) (int64, error) | ||||||
| 	Get(shortId uint64) (Website, error) | 	Get(shortId uint64) (Website, error) | ||||||
| 	GetById(id int64) (Website, error) |  | ||||||
| 	GetAllUser(userId int64) ([]Website, error) | 	GetAllUser(userId int64) ([]Website, error) | ||||||
| 	GetAll() ([]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) { | func (m *WebsiteModel) Insert(shortId uint64, userId int64, siteName, siteUrl, authorName string) (int64, error) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user