github.com/turgay/mattermost-server@v5.3.2-0.20181002173352-2945e8a2b0ce+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  
    11  func TestGetBrandImage(t *testing.T) {
    12  	th := Setup().InitBasic().InitSystemAdmin()
    13  	defer th.TearDown()
    14  	Client := th.Client
    15  
    16  	_, resp := Client.GetBrandImage()
    17  	CheckNotFoundStatus(t, resp)
    18  
    19  	Client.Logout()
    20  	_, resp = Client.GetBrandImage()
    21  	CheckNotFoundStatus(t, resp)
    22  
    23  	_, resp = th.SystemAdminClient.GetBrandImage()
    24  	CheckNotFoundStatus(t, resp)
    25  }
    26  
    27  func TestUploadBrandImage(t *testing.T) {
    28  	th := Setup().InitBasic().InitSystemAdmin()
    29  	defer th.TearDown()
    30  	Client := th.Client
    31  
    32  	data, err := readTestFile("test.png")
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  
    37  	_, resp := Client.UploadBrandImage(data)
    38  	CheckForbiddenStatus(t, resp)
    39  
    40  	// status code returns either forbidden or unauthorized
    41  	// note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server
    42  	Client.Logout()
    43  	_, resp = Client.UploadBrandImage(data)
    44  	if resp.StatusCode == http.StatusForbidden {
    45  		CheckForbiddenStatus(t, resp)
    46  	} else if resp.StatusCode == http.StatusUnauthorized {
    47  		CheckUnauthorizedStatus(t, resp)
    48  	} else {
    49  		t.Fatal("Should have failed either forbidden or unauthorized")
    50  	}
    51  
    52  	_, resp = th.SystemAdminClient.UploadBrandImage(data)
    53  	CheckCreatedStatus(t, resp)
    54  }