summaryrefslogtreecommitdiffstats
path: root/api4/file_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-14 04:40:32 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-03-13 15:40:32 -0400
commit8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e (patch)
tree050afb6fe109b9366831d6274e88a01d70fc074b /api4/file_test.go
parentc84b761e751ae1c9fbd55bd0b01193cb3dc72b67 (diff)
downloadchat-8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e.tar.gz
chat-8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e.tar.bz2
chat-8b59a2a2914d7ac0b9f318e6d3208e31fa9dd88e.zip
APIv4: GET /files/{file_id}/preview (#5568)
patch 1
Diffstat (limited to 'api4/file_test.go')
-rw-r--r--api4/file_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/api4/file_test.go b/api4/file_test.go
index d6de56b7d..be4f4a59c 100644
--- a/api4/file_test.go
+++ b/api4/file_test.go
@@ -277,3 +277,55 @@ func TestGetFileLink(t *testing.T) {
cleanupTestFile(result.Data.(*model.FileInfo))
}
}
+
+func TestGetFilePreview(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ 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)
+
+ data, resp := Client.GetFilePreview(fileId)
+ CheckNoError(t, resp)
+
+ if data == nil || len(data) == 0 {
+ t.Fatal("should not be empty")
+ }
+
+ _, resp = Client.GetFilePreview("junk")
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetFilePreview(model.NewId())
+ CheckNotFoundStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.GetFilePreview(fileId)
+ CheckUnauthorizedStatus(t, resp)
+
+ otherUser := th.CreateUser()
+ Client.Login(otherUser.Email, otherUser.Password)
+ _, resp = Client.GetFilePreview(fileId)
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = th.SystemAdminClient.GetFilePreview(fileId)
+ CheckNoError(t, resp)
+}