github.com/mad-app/mattermost-server@v5.11.1+incompatible/store/storetest/user_terms_of_service.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package storetest
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  	"github.com/mattermost/mattermost-server/store"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestUserTermsOfServiceStore(t *testing.T, ss store.Store) {
    15  	t.Run("TestSaveUserTermsOfService", func(t *testing.T) { testSaveUserTermsOfService(t, ss) })
    16  	t.Run("TestGetByUserTermsOfService", func(t *testing.T) { testGetByUserTermsOfService(t, ss) })
    17  	t.Run("TestDeleteUserTermsOfService", func(t *testing.T) { testDeleteUserTermsOfService(t, ss) })
    18  }
    19  
    20  func testSaveUserTermsOfService(t *testing.T, ss store.Store) {
    21  	userTermsOfService := &model.UserTermsOfService{
    22  		UserId:           model.NewId(),
    23  		TermsOfServiceId: model.NewId(),
    24  	}
    25  
    26  	r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
    27  	if r1.Err != nil {
    28  		t.Fatal(r1.Err)
    29  	}
    30  
    31  	savedUserTermsOfService := r1.Data.(*model.UserTermsOfService)
    32  	assert.Equal(t, userTermsOfService.UserId, savedUserTermsOfService.UserId)
    33  	assert.Equal(t, userTermsOfService.TermsOfServiceId, savedUserTermsOfService.TermsOfServiceId)
    34  	assert.NotEmpty(t, savedUserTermsOfService.CreateAt)
    35  }
    36  
    37  func testGetByUserTermsOfService(t *testing.T, ss store.Store) {
    38  	userTermsOfService := &model.UserTermsOfService{
    39  		UserId:           model.NewId(),
    40  		TermsOfServiceId: model.NewId(),
    41  	}
    42  
    43  	r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
    44  	if r1.Err != nil {
    45  		t.Fatal(r1.Err)
    46  	}
    47  
    48  	r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
    49  	if r1.Err != nil {
    50  		t.Fatal(r1.Err)
    51  	}
    52  
    53  	fetchedUserTermsOfService := r1.Data.(*model.UserTermsOfService)
    54  	assert.Equal(t, userTermsOfService.UserId, fetchedUserTermsOfService.UserId)
    55  	assert.Equal(t, userTermsOfService.TermsOfServiceId, fetchedUserTermsOfService.TermsOfServiceId)
    56  	assert.NotEmpty(t, fetchedUserTermsOfService.CreateAt)
    57  }
    58  
    59  func testDeleteUserTermsOfService(t *testing.T, ss store.Store) {
    60  	userTermsOfService := &model.UserTermsOfService{
    61  		UserId:           model.NewId(),
    62  		TermsOfServiceId: model.NewId(),
    63  	}
    64  
    65  	r1 := <-ss.UserTermsOfService().Save(userTermsOfService)
    66  	if r1.Err != nil {
    67  		t.Fatal(r1.Err)
    68  	}
    69  
    70  	r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
    71  	if r1.Err != nil {
    72  		t.Fatal(r1.Err)
    73  	}
    74  
    75  	r1 = <-ss.UserTermsOfService().Delete(userTermsOfService.UserId, userTermsOfService.TermsOfServiceId)
    76  	if r1.Err != nil {
    77  		t.Fatal(r1.Err)
    78  	}
    79  
    80  	r1 = <-ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
    81  	assert.Equal(t, "store.sql_user_terms_of_service.get_by_user.no_rows.app_error", r1.Err.Id)
    82  }