Model refactor, part 3 (#4152)

* Remove manager.Repository
* Refactor other repositories
* Fix tests and add database mock
* Add AssertExpectations method
* Refactor routes
* Move default movie image to internal/static and add convenience methods
* Refactor default performer image boxes
This commit is contained in:
DingDongSoLong4
2023-10-16 05:26:34 +02:00
committed by GitHub
parent 40bcb4baa5
commit 33f2ebf2a3
87 changed files with 1843 additions and 1651 deletions

View File

@@ -1,7 +1,6 @@
package studio
import (
"context"
"errors"
"github.com/stashapp/stash/pkg/models"
@@ -162,27 +161,26 @@ func initTestTable() {
func TestToJSON(t *testing.T) {
initTestTable()
ctx := context.Background()
mockStudioReader := &mocks.StudioReaderWriter{}
db := mocks.NewDatabase()
imageErr := errors.New("error getting image")
mockStudioReader.On("GetImage", ctx, studioID).Return(imageBytes, nil).Once()
mockStudioReader.On("GetImage", ctx, noImageID).Return(nil, nil).Once()
mockStudioReader.On("GetImage", ctx, errImageID).Return(nil, imageErr).Once()
mockStudioReader.On("GetImage", ctx, missingParentStudioID).Return(imageBytes, nil).Maybe()
mockStudioReader.On("GetImage", ctx, errStudioID).Return(imageBytes, nil).Maybe()
db.Studio.On("GetImage", testCtx, studioID).Return(imageBytes, nil).Once()
db.Studio.On("GetImage", testCtx, noImageID).Return(nil, nil).Once()
db.Studio.On("GetImage", testCtx, errImageID).Return(nil, imageErr).Once()
db.Studio.On("GetImage", testCtx, missingParentStudioID).Return(imageBytes, nil).Maybe()
db.Studio.On("GetImage", testCtx, errStudioID).Return(imageBytes, nil).Maybe()
parentStudioErr := errors.New("error getting parent studio")
mockStudioReader.On("Find", ctx, parentStudioID).Return(&parentStudio, nil)
mockStudioReader.On("Find", ctx, missingStudioID).Return(nil, nil)
mockStudioReader.On("Find", ctx, errParentStudioID).Return(nil, parentStudioErr)
db.Studio.On("Find", testCtx, parentStudioID).Return(&parentStudio, nil)
db.Studio.On("Find", testCtx, missingStudioID).Return(nil, nil)
db.Studio.On("Find", testCtx, errParentStudioID).Return(nil, parentStudioErr)
for i, s := range scenarios {
studio := s.input
json, err := ToJSON(ctx, mockStudioReader, &studio)
json, err := ToJSON(testCtx, db.Studio, &studio)
switch {
case !s.err && err != nil:
@@ -194,5 +192,5 @@ func TestToJSON(t *testing.T) {
}
}
mockStudioReader.AssertExpectations(t)
db.AssertExpectations(t)
}