github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/app/status_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/v5/model"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestSaveStatus(t *testing.T) {
    14  	th := Setup(t).InitBasic()
    15  	defer th.TearDown()
    16  
    17  	user := th.BasicUser
    18  
    19  	for _, statusString := range []string{
    20  		model.STATUS_ONLINE,
    21  		model.STATUS_AWAY,
    22  		model.STATUS_DND,
    23  		model.STATUS_OFFLINE,
    24  	} {
    25  		t.Run(statusString, func(t *testing.T) {
    26  			status := &model.Status{
    27  				UserId: user.Id,
    28  				Status: statusString,
    29  			}
    30  
    31  			th.App.SaveAndBroadcastStatus(status)
    32  
    33  			after, err := th.App.GetStatus(user.Id)
    34  			require.Nil(t, err, "failed to get status after save: %v", err)
    35  			require.Equal(t, statusString, after.Status, "failed to save status, got %v, expected %v", after.Status, statusString)
    36  		})
    37  	}
    38  }