diff options
author | George Goldberg <george@gberg.me> | 2017-02-24 17:33:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-24 17:33:59 +0000 |
commit | f182d196fffc9da89ad63bdbd7bbb2e41da3146e (patch) | |
tree | 45d8aaad6ffc335dd40db225f2775d3204fcc812 /store/sql_user_store_test.go | |
parent | ba028ed74b69bd1dd902344663fbf8ba4f1dfb87 (diff) | |
download | chat-f182d196fffc9da89ad63bdbd7bbb2e41da3146e.tar.gz chat-f182d196fffc9da89ad63bdbd7bbb2e41da3146e.tar.bz2 chat-f182d196fffc9da89ad63bdbd7bbb2e41da3146e.zip |
PLT-5070: Server side component of Telemetry. (#5514)
Diffstat (limited to 'store/sql_user_store_test.go')
-rw-r--r-- | store/sql_user_store_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index f7236659b..c46a32ec1 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -1477,3 +1477,70 @@ func TestUserStoreSearch(t *testing.T) { } } } + +func TestUserStoreAnalyticsGetInactiveUsersCount(t *testing.T) { + Setup() + + u1 := &model.User{} + u1.Email = model.NewId() + Must(store.User().Save(u1)) + + var count int64 + + if result := <-store.User().AnalyticsGetInactiveUsersCount(); result.Err != nil { + t.Fatal(result.Err) + } else { + count = result.Data.(int64) + } + + u2 := &model.User{} + u2.Email = model.NewId() + u2.DeleteAt = model.GetMillis() + Must(store.User().Save(u2)) + + if result := <-store.User().AnalyticsGetInactiveUsersCount(); result.Err != nil { + t.Fatal(result.Err) + } else { + newCount := result.Data.(int64) + if count != newCount-1 { + t.Fatal("Expected 1 more inactive users but found otherwise.", count, newCount) + } + } +} + +func TestUserStoreAnalyticsGetSystemAdminCount(t *testing.T) { + Setup() + + var countBefore int64 + if result := <-store.User().AnalyticsGetSystemAdminCount(); result.Err != nil { + t.Fatal(result.Err) + } else { + countBefore = result.Data.(int64) + } + + u1 := model.User{} + u1.Email = model.NewId() + u1.Username = model.NewId() + u1.Roles = "system_user system_admin" + + u2 := model.User{} + u2.Email = model.NewId() + u2.Username = model.NewId() + + if err := (<-store.User().Save(&u1)).Err; err != nil { + t.Fatal("couldn't save user", err) + } + + if err := (<-store.User().Save(&u2)).Err; err != nil { + t.Fatal("couldn't save user", err) + } + + if result := <-store.User().AnalyticsGetSystemAdminCount(); result.Err != nil { + t.Fatal(result.Err) + } else { + // We expect to find 1 more system admin than there was at the start of this test function. + if count := result.Data.(int64); count != countBefore+1 { + t.Fatal("Did not get the expected number of system admins. Expected, got: ", countBefore+1, count) + } + } +} |