@@ -13,6 +13,7 @@ import (
1313 "go.uber.org/mock/gomock"
1414
1515 "github.com/lbrty/observer/internal/domain/document"
16+ "github.com/lbrty/observer/internal/domain/person"
1617 "github.com/lbrty/observer/internal/handler/handlertest"
1718 "github.com/lbrty/observer/internal/handler/project"
1819 "github.com/lbrty/observer/internal/middleware"
@@ -43,8 +44,12 @@ func newMultipartUploadContext(filename string, content []byte, projectID, perso
4344
4445func newDocumentHandler (ctrl * gomock.Controller ) (* project.DocumentHandler , * repomock.MockDocumentRepository , * storagemock.MockFileStorage ) {
4546 docRepo := repomock .NewMockDocumentRepository (ctrl )
47+ personRepo := repomock .NewMockPersonRepository (ctrl )
4648 fs := storagemock .NewMockFileStorage (ctrl )
47- uc := ucproject .NewDocumentUseCase (docRepo , fs , nil )
49+ personRepo .EXPECT ().GetByID (gomock .Any (), gomock .Any ()).AnyTimes ().DoAndReturn (func (_ any , id string ) (* person.Person , error ) {
50+ return & person.Person {ID : id , ProjectID : "x" }, nil
51+ })
52+ uc := ucproject .NewDocumentUseCase (docRepo , personRepo , fs , nil )
4853 return project .NewDocumentHandler (uc ), docRepo , fs
4954}
5055
@@ -58,6 +63,7 @@ func TestDocumentHandler_List_NoPermission(t *testing.T) {
5863
5964 personID := handlertest .TestID ().String ()
6065 c , w := handlertest .NewTestContextWithParams (http .MethodGet , "/projects/x/people/" + personID + "/documents" , nil , gin.Params {
66+ {Key : "project_id" , Value : "x" },
6167 {Key : "person_id" , Value : personID },
6268 })
6369 setCanViewDocuments (c , false )
@@ -78,6 +84,7 @@ func TestDocumentHandler_List_Success(t *testing.T) {
7884 }, nil )
7985
8086 c , w := handlertest .NewTestContextWithParams (http .MethodGet , "/projects/x/people/" + personID + "/documents" , nil , gin.Params {
87+ {Key : "project_id" , Value : "x" },
8188 {Key : "person_id" , Value : personID },
8289 })
8390 setCanViewDocuments (c , true )
@@ -241,7 +248,7 @@ func TestDocumentHandler_Upload_RejectsForbiddenMIME(t *testing.T) {
241248 ctrl := gomock .NewController (t )
242249 h , _ , _ := newDocumentHandler (ctrl )
243250
244- projectID := handlertest . TestID (). String ()
251+ projectID := "x"
245252 personID := handlertest .TestID ().String ()
246253
247254 htmlContent := []byte ("<html><body><script>alert(1)</script></body></html>" )
@@ -257,7 +264,7 @@ func TestDocumentHandler_Upload_RejectsXMLSVG(t *testing.T) {
257264 ctrl := gomock .NewController (t )
258265 h , _ , _ := newDocumentHandler (ctrl )
259266
260- projectID := handlertest . TestID (). String ()
267+ projectID := "x"
261268 personID := handlertest .TestID ().String ()
262269
263270 svgContent := []byte (`<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>` )
@@ -273,7 +280,7 @@ func TestDocumentHandler_Upload_SanitizesFilename(t *testing.T) {
273280 ctrl := gomock .NewController (t )
274281 h , docRepo , fs := newDocumentHandler (ctrl )
275282
276- projectID := handlertest . TestID (). String ()
283+ projectID := "x"
277284 personID := handlertest .TestID ().String ()
278285
279286 docRepo .EXPECT ().Create (gomock .Any (), gomock .Any ()).Return (nil )
0 commit comments