summaryrefslogtreecommitdiffstats
path: root/api4/file_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-14 05:34:43 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-03-13 16:34:43 -0400
commit3cbe05e0f48673adf0306cc1fcb97eb224c375ac (patch)
treec8953e75037452a78d75bbe832cf0f3b467d3470 /api4/file_test.go
parent8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e (diff)
downloadchat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.tar.gz
chat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.tar.bz2
chat-3cbe05e0f48673adf0306cc1fcb97eb224c375ac.zip
APIv4: GET /files/{file_id}/info (#5591)
Diffstat (limited to 'api4/file_test.go')
-rw-r--r--api4/file_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/api4/file_test.go b/api4/file_test.go
index be4f4a59c..f257ec074 100644
--- a/api4/file_test.go
+++ b/api4/file_test.go
@@ -329,3 +329,70 @@ func TestGetFilePreview(t *testing.T) {
_, resp = th.SystemAdminClient.GetFilePreview(fileId)
CheckNoError(t, resp)
}
+
+func TestGetFileInfo(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ user := th.BasicUser
+ channel := th.BasicChannel
+
+ if utils.Cfg.FileSettings.DriverName == "" {
+ t.Skip("skipping because no file driver is enabled")
+ }
+
+ fileId := ""
+ var sent []byte
+ var err error
+ if sent, err = readTestFile("test.png"); err != nil {
+ t.Fatal(err)
+ } else {
+ fileResp, resp := Client.UploadFile(sent, channel.Id, "test.png")
+ CheckNoError(t, resp)
+
+ fileId = fileResp.FileInfos[0].Id
+ }
+
+ // Wait a bit for files to ready
+ time.Sleep(2 * time.Second)
+
+ info, resp := Client.GetFileInfo(fileId)
+ CheckNoError(t, resp)
+
+ if err != nil {
+ t.Fatal(err)
+ } else if info.Id != fileId {
+ t.Fatal("got incorrect file")
+ } else if info.CreatorId != user.Id {
+ t.Fatal("file should be assigned to user")
+ } else if info.PostId != "" {
+ t.Fatal("file shouldn't have a post")
+ } else if info.Path != "" {
+ t.Fatal("file path shouldn't have been returned to client")
+ } else if info.ThumbnailPath != "" {
+ t.Fatal("file thumbnail path shouldn't have been returned to client")
+ } else if info.PreviewPath != "" {
+ t.Fatal("file preview path shouldn't have been returned to client")
+ } else if info.MimeType != "image/png" {
+ t.Fatal("mime type should've been image/png")
+ }
+
+ _, resp = Client.GetFileInfo("junk")
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetFileInfo(model.NewId())
+ CheckNotFoundStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetFileInfo(fileId)
+ CheckUnauthorizedStatus(t, resp)
+
+ otherUser := th.CreateUser()
+ Client.Login(otherUser.Email, otherUser.Password)
+ _, resp = Client.GetFileInfo(fileId)
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = th.SystemAdminClient.GetFileInfo(fileId)
+ CheckNoError(t, resp)
+}