Backend: Add tests to internal/api
This commit is contained in:
parent
e3993b3dbf
commit
afc1e10646
5 changed files with 200 additions and 0 deletions
30
internal/api/import_test.go
Normal file
30
internal/api/import_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tidwall/gjson"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetImportOptions(t *testing.T) {
|
||||
t.Run("successful request", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetImportOptions(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/import")
|
||||
val := gjson.Get(r.Body.String(), "dirs")
|
||||
assert.Equal(t, "[\"/raw\"]", val.String())
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCancelImport(t *testing.T) {
|
||||
t.Run("successful request", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
CancelImport(router, conf)
|
||||
r := PerformRequest(app, "DELETE", "/api/v1/import")
|
||||
val := gjson.Get(r.Body.String(), "message")
|
||||
assert.Equal(t, "import canceled", val.String())
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
30
internal/api/index_test.go
Normal file
30
internal/api/index_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tidwall/gjson"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetIndexingOptions(t *testing.T) {
|
||||
t.Run("successful request", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetIndexingOptions(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/index")
|
||||
val := gjson.Get(r.Body.String(), "dirs")
|
||||
assert.Contains(t, val.String(), "/2011")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCancelIndex(t *testing.T) {
|
||||
t.Run("successful request", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
CancelIndexing(router, conf)
|
||||
r := PerformRequest(app, "DELETE", "/api/v1/index")
|
||||
val := gjson.Get(r.Body.String(), "message")
|
||||
assert.Equal(t, "indexing canceled", val.String())
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
34
internal/api/video_test.go
Normal file
34
internal/api/video_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetVideo(t *testing.T) {
|
||||
t.Run("invalid hash", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetVideo(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/videos/xxx/mp4")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("invalid type", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetVideo(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/xxx")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("file for video not found", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetVideo(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd831/mp4")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
t.Run("file with error", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
GetVideo(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/videos/acad9168fa6acc5c5c2965ddf6ec465ca42fd832/mp4")
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
28
internal/api/websocket_test.go
Normal file
28
internal/api/websocket_test.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWebsocket(t *testing.T) {
|
||||
t.Run("bad request", func(t *testing.T) {
|
||||
app, router, conf := NewApiTest()
|
||||
Websocket(router, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/ws")
|
||||
assert.Equal(t, http.StatusBadRequest, r.Code)
|
||||
})
|
||||
t.Run("router nil", func(t *testing.T) {
|
||||
app, _, conf := NewApiTest()
|
||||
Websocket(nil, conf)
|
||||
r := PerformRequest(app, "GET", "/api/v1/ws")
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
})
|
||||
t.Run("conf nil", func(t *testing.T) {
|
||||
app, router, _ := NewApiTest()
|
||||
Websocket(router, nil)
|
||||
r := PerformRequest(app, "GET", "/api/v1/ws")
|
||||
assert.Equal(t, http.StatusNotFound, r.Code)
|
||||
})
|
||||
}
|
|
@ -320,6 +320,84 @@ var FileFixtures = map[string]File{
|
|||
UpdatedIn: 0,
|
||||
DeletedAt: nil,
|
||||
},
|
||||
"Video.mp4": {
|
||||
ID: 1000008,
|
||||
Photo: PhotoFixtures.Pointer("Photo10"),
|
||||
PhotoID: 1000010,
|
||||
PhotoUUID: "pt9jtdre2lvl0y17",
|
||||
FileUUID: "ft71s39w45bnlqdw",
|
||||
FileName: "Video.mp4",
|
||||
OriginalName: "Video.mp4",
|
||||
FileHash: "acad9168fa6acc5c5c2965ddf6ec465ca42fd831",
|
||||
FileModified: time.Date(2017, 1, 6, 2, 6, 51, 0, time.UTC),
|
||||
FileSize: 500,
|
||||
FileType: "mp4",
|
||||
FileMime: "video/mp4",
|
||||
FilePrimary: true,
|
||||
FileSidecar: false,
|
||||
FileVideo: true,
|
||||
FileMissing: false,
|
||||
FileDuplicate: false,
|
||||
FilePortrait: false,
|
||||
FileWidth: 1200,
|
||||
FileHeight: 1600,
|
||||
FileOrientation: 6,
|
||||
FileAspectRatio: 0.75,
|
||||
FileMainColor: "green",
|
||||
FileColors: "266111000",
|
||||
FileLuminance: "DC42844C8",
|
||||
FileDiff: 800,
|
||||
FileChroma: 0,
|
||||
FileNotes: "",
|
||||
FileError: "",
|
||||
Share: []FileShare{},
|
||||
Sync: []FileSync{},
|
||||
Links: []Link{},
|
||||
CreatedAt: time.Date(2018, 1, 1, 2, 6, 51, 0, time.UTC),
|
||||
CreatedIn: 2,
|
||||
UpdatedAt: time.Date(2029, 3, 28, 14, 6, 0, 0, time.UTC),
|
||||
UpdatedIn: 0,
|
||||
DeletedAt: nil,
|
||||
},
|
||||
"VideoWithError.mp4": {
|
||||
ID: 1000009,
|
||||
Photo: PhotoFixtures.Pointer("Photo10"),
|
||||
PhotoID: 1000010,
|
||||
PhotoUUID: "pt9jtdre2lvl0y17",
|
||||
FileUUID: "ft72s39w45bnlqdw",
|
||||
FileName: "VideoError.mp4",
|
||||
OriginalName: "VideoError.mp4",
|
||||
FileHash: "acad9168fa6acc5c5c2965ddf6ec465ca42fd832",
|
||||
FileModified: time.Date(2017, 1, 6, 2, 6, 51, 0, time.UTC),
|
||||
FileSize: 500,
|
||||
FileType: "mp4",
|
||||
FileMime: "video/mp4",
|
||||
FilePrimary: false,
|
||||
FileSidecar: false,
|
||||
FileVideo: true,
|
||||
FileMissing: false,
|
||||
FileDuplicate: false,
|
||||
FilePortrait: false,
|
||||
FileWidth: 1200,
|
||||
FileHeight: 1600,
|
||||
FileOrientation: 6,
|
||||
FileAspectRatio: 0.75,
|
||||
FileMainColor: "green",
|
||||
FileColors: "266111000",
|
||||
FileLuminance: "DC42844C8",
|
||||
FileDiff: 800,
|
||||
FileChroma: 0,
|
||||
FileNotes: "",
|
||||
FileError: "Error",
|
||||
Share: []FileShare{},
|
||||
Sync: []FileSync{},
|
||||
Links: []Link{},
|
||||
CreatedAt: time.Date(2018, 1, 1, 2, 6, 51, 0, time.UTC),
|
||||
CreatedIn: 2,
|
||||
UpdatedAt: time.Date(2029, 3, 28, 14, 6, 0, 0, time.UTC),
|
||||
UpdatedIn: 0,
|
||||
DeletedAt: nil,
|
||||
},
|
||||
}
|
||||
|
||||
var FileFixturesExampleJPG = FileFixtures["exampleFileName.jpg"]
|
||||
|
|
Loading…
Reference in a new issue