github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api/command_statuses_test.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/mattermost/mattermost-server/model"
    11  )
    12  
    13  func TestStatusCommands(t *testing.T) {
    14  	th := Setup().InitBasic()
    15  	defer th.TearDown()
    16  
    17  	commandAndTest(t, th, "away")
    18  	commandAndTest(t, th, "offline")
    19  	commandAndTest(t, th, "online")
    20  }
    21  
    22  func commandAndTest(t *testing.T, th *TestHelper, status string) {
    23  	Client := th.BasicClient
    24  	channel := th.BasicChannel
    25  	user := th.BasicUser
    26  
    27  	r1 := Client.Must(Client.Command(channel.Id, "/"+status)).Data.(*model.CommandResponse)
    28  	if r1 == nil {
    29  		t.Fatal("Command failed to execute")
    30  	}
    31  
    32  	time.Sleep(1000 * time.Millisecond)
    33  
    34  	statuses := Client.Must(Client.GetStatuses()).Data.(map[string]string)
    35  
    36  	if status == "offline" {
    37  		status = ""
    38  	}
    39  	if statuses[user.Id] != status {
    40  		t.Fatal("Error setting status " + status)
    41  	}
    42  }