-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
user_terms_of_service.go
67 lines (53 loc) · 2.43 KB
/
user_terms_of_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package storetest
import (
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUserTermsOfServiceStore(t *testing.T, ss store.Store) {
t.Run("TestSaveUserTermsOfService", func(t *testing.T) { testSaveUserTermsOfService(t, ss) })
t.Run("TestGetByUserTermsOfService", func(t *testing.T) { testGetByUserTermsOfService(t, ss) })
t.Run("TestDeleteUserTermsOfService", func(t *testing.T) { testDeleteUserTermsOfService(t, ss) })
}
func testSaveUserTermsOfService(t *testing.T, ss store.Store) {
userTermsOfService := &model.UserTermsOfService{
UserId: model.NewId(),
TermsOfServiceId: model.NewId(),
}
savedUserTermsOfService, err := ss.UserTermsOfService().Save(userTermsOfService)
require.Nil(t, err)
assert.Equal(t, userTermsOfService.UserId, savedUserTermsOfService.UserId)
assert.Equal(t, userTermsOfService.TermsOfServiceId, savedUserTermsOfService.TermsOfServiceId)
assert.NotEmpty(t, savedUserTermsOfService.CreateAt)
}
func testGetByUserTermsOfService(t *testing.T, ss store.Store) {
userTermsOfService := &model.UserTermsOfService{
UserId: model.NewId(),
TermsOfServiceId: model.NewId(),
}
_, err := ss.UserTermsOfService().Save(userTermsOfService)
require.Nil(t, err)
fetchedUserTermsOfService, err := ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
require.Nil(t, err)
assert.Equal(t, userTermsOfService.UserId, fetchedUserTermsOfService.UserId)
assert.Equal(t, userTermsOfService.TermsOfServiceId, fetchedUserTermsOfService.TermsOfServiceId)
assert.NotEmpty(t, fetchedUserTermsOfService.CreateAt)
}
func testDeleteUserTermsOfService(t *testing.T, ss store.Store) {
userTermsOfService := &model.UserTermsOfService{
UserId: model.NewId(),
TermsOfServiceId: model.NewId(),
}
_, err := ss.UserTermsOfService().Save(userTermsOfService)
require.Nil(t, err)
_, err = ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
require.Nil(t, err)
err = ss.UserTermsOfService().Delete(userTermsOfService.UserId, userTermsOfService.TermsOfServiceId)
require.Nil(t, err)
_, err = ss.UserTermsOfService().GetByUser(userTermsOfService.UserId)
assert.Equal(t, "store.sql_user_terms_of_service.get_by_user.no_rows.app_error", err.Id)
}