github.com/kongr45gpen/mattermost-server@v5.11.1+incompatible/api4/brand_test.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  
    10  	"github.com/mattermost/mattermost-server/utils/testutils"
    11  )
    12  
    13  func TestGetBrandImage(t *testing.T) {
    14  	th := Setup().InitBasic()
    15  	defer th.TearDown()
    16  	Client := th.Client
    17  
    18  	_, resp := Client.GetBrandImage()
    19  	CheckNotFoundStatus(t, resp)
    20  
    21  	Client.Logout()
    22  	_, resp = Client.GetBrandImage()
    23  	CheckNotFoundStatus(t, resp)
    24  
    25  	_, resp = th.SystemAdminClient.GetBrandImage()
    26  	CheckNotFoundStatus(t, resp)
    27  }
    28  
    29  func TestUploadBrandImage(t *testing.T) {
    30  	th := Setup().InitBasic()
    31  	defer th.TearDown()
    32  	Client := th.Client
    33  
    34  	data, err := testutils.ReadTestFile("test.png")
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  
    39  	_, resp := Client.UploadBrandImage(data)
    40  	CheckForbiddenStatus(t, resp)
    41  
    42  	// status code returns either forbidden or unauthorized
    43  	// note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server
    44  	Client.Logout()
    45  	_, resp = Client.UploadBrandImage(data)
    46  	if resp.StatusCode == http.StatusForbidden {
    47  		CheckForbiddenStatus(t, resp)
    48  	} else if resp.StatusCode == http.StatusUnauthorized {
    49  		CheckUnauthorizedStatus(t, resp)
    50  	} else {
    51  		t.Fatal("Should have failed either forbidden or unauthorized")
    52  	}
    53  
    54  	_, resp = th.SystemAdminClient.UploadBrandImage(data)
    55  	CheckCreatedStatus(t, resp)
    56  }
    57  
    58  func TestDeleteBrandImage(t *testing.T) {
    59  	th := Setup().InitBasic()
    60  	defer th.TearDown()
    61  
    62  	data, err := testutils.ReadTestFile("test.png")
    63  	if err != nil {
    64  		t.Fatal(err)
    65  	}
    66  
    67  	_, resp := th.SystemAdminClient.UploadBrandImage(data)
    68  	CheckCreatedStatus(t, resp)
    69  
    70  	resp = th.Client.DeleteBrandImage()
    71  	CheckForbiddenStatus(t, resp)
    72  
    73  	th.Client.Logout()
    74  
    75  	resp = th.Client.DeleteBrandImage()
    76  	CheckUnauthorizedStatus(t, resp)
    77  
    78  	resp = th.SystemAdminClient.DeleteBrandImage()
    79  	CheckOKStatus(t, resp)
    80  
    81  	resp = th.SystemAdminClient.DeleteBrandImage()
    82  	CheckNotFoundStatus(t, resp)
    83  }