Skip to content

Commit 1efb353

Browse files
author
vuong
committed
test UploadDocument
1 parent 5dc7bb2 commit 1efb353

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

backend/endpoints/tests/volume_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,56 @@ import (
1616
)
1717

1818
func TestUploadDocument(t *testing.T) {
19+
controller := gomock.NewController(t)
20+
assert := assert.New(t)
21+
defer controller.Finish()
22+
23+
// ==== test setup =====
24+
entityID := uuid.New()
25+
parentID := uuid.New()
26+
entityToCreate := repositories.FilesystemEntry{
27+
LogicalName: "file",
28+
ParentFileID: parentID,
29+
IsDocument: true,
30+
OwnerUserId: 1,
31+
}
32+
33+
mockFileRepo := repMocks.NewMockIFilesystemRepository(controller)
34+
mockFileRepo.EXPECT().CreateEntry(entityToCreate).Return(repositories.FilesystemEntry{
35+
EntityID: entityID,
36+
LogicalName: "file",
37+
ParentFileID: parentID,
38+
IsDocument: true,
39+
OwnerUserId: 1,
40+
}, nil).Times(1)
41+
42+
expected, _ := ioutil.TempFile(os.TempDir(), "file")
43+
defer os.Remove(expected.Name())
44+
45+
mockDockerFileSystemRepo := repMocks.NewMockIUnpublishedVolumeRepository(controller)
46+
mockDockerFileSystemRepo.EXPECT().GetFromVolume(entityID.String()).Return(expected, nil).Times(1)
47+
48+
mockDepFactory := createMockDependencyFactory(controller, mockFileRepo, true)
49+
mockDepFactory.EXPECT().GetUnpublishedVolumeRepo().Return(mockDockerFileSystemRepo)
50+
51+
const fileContent = "Hello World"
52+
53+
form := models.ValidDocumentUploadRequest{
54+
Parent: parentID,
55+
DocumentName: "file",
56+
Content: fileContent,
57+
}
58+
59+
response := endpoints.UploadDocument(form, mockDepFactory)
60+
assert.Equal(response.Status, http.StatusOK)
61+
assert.Equal(response.Response, models.NewEntityResponse{
62+
NewID: entityID,
63+
})
64+
65+
// check that the file was written to the docker volume
66+
actual, _ := ioutil.ReadFile(expected.Name())
67+
assert.Equal(actual, []byte(fileContent))
68+
1969
}
2070

2171
func TestGetPublishedDocument(t *testing.T) {

0 commit comments

Comments
 (0)