summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-01-22 10:19:02 -0500
committerJoramWilander <jwawilander@gmail.com>2016-01-22 10:19:02 -0500
commit0d239a1a9e82a1279685b8962920eaf5c1b8f571 (patch)
tree518a39691c116d24be1e9aa4d19afbbcc95572da
parentbbcf00f02e469bcf04a45c1cdf8a7932e30ccfc0 (diff)
downloadchat-0d239a1a9e82a1279685b8962920eaf5c1b8f571.tar.gz
chat-0d239a1a9e82a1279685b8962920eaf5c1b8f571.tar.bz2
chat-0d239a1a9e82a1279685b8962920eaf5c1b8f571.zip
Added unit test and fixed errors
-rw-r--r--api/admin_test.go70
-rw-r--r--model/client.go11
-rw-r--r--web/react/components/admin_console/analytics.jsx4
-rw-r--r--web/react/components/admin_console/system_analytics.jsx2
4 files changed, 76 insertions, 11 deletions
diff --git a/api/admin_test.go b/api/admin_test.go
index f7b6a7eeb..c2f4e9c76 100644
--- a/api/admin_test.go
+++ b/api/admin_test.go
@@ -151,7 +151,7 @@ func TestEmailTest(t *testing.T) {
}
}
-func TestGetAnalyticsStandard(t *testing.T) {
+func TestGetTeamAnalyticsStandard(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
@@ -169,7 +169,7 @@ func TestGetAnalyticsStandard(t *testing.T) {
post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
- if _, err := Client.GetAnalytics(team.Id, "standard"); err == nil {
+ if _, err := Client.GetTeamAnalytics(team.Id, "standard"); err == nil {
t.Fatal("Shouldn't have permissions")
}
@@ -180,7 +180,7 @@ func TestGetAnalyticsStandard(t *testing.T) {
Client.LoginByEmail(team.Name, user.Email, "pwd")
- if result, err := Client.GetAnalytics(team.Id, "standard"); err != nil {
+ if result, err := Client.GetTeamAnalytics(team.Id, "standard"); err != nil {
t.Fatal(err)
} else {
rows := result.Data.(model.AnalyticsRows)
@@ -214,6 +214,62 @@ func TestGetAnalyticsStandard(t *testing.T) {
t.Log(rows.ToJson())
t.Fatal()
}
+
+ if rows[3].Name != "unique_user_count" {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[3].Value != 1 {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+ }
+
+ if result, err := Client.GetSystemAnalytics("standard"); err != nil {
+ t.Fatal(err)
+ } else {
+ rows := result.Data.(model.AnalyticsRows)
+
+ if rows[0].Name != "channel_open_count" {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[0].Value < 2 {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[1].Name != "channel_private_count" {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[1].Value == 0 {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[2].Name != "post_count" {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[2].Value == 0 {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[3].Name != "unique_user_count" {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
+
+ if rows[3].Value == 0 {
+ t.Log(rows.ToJson())
+ t.Fatal()
+ }
}
}
@@ -239,7 +295,7 @@ func TestGetPostCount(t *testing.T) {
Srv.Store.(*store.SqlStore).GetMaster().Exec("UPDATE Posts SET CreateAt = :CreateAt WHERE ChannelId = :ChannelId",
map[string]interface{}{"ChannelId": channel1.Id, "CreateAt": utils.MillisFromTime(utils.Yesterday())})
- if _, err := Client.GetAnalytics(team.Id, "post_counts_day"); err == nil {
+ if _, err := Client.GetTeamAnalytics(team.Id, "post_counts_day"); err == nil {
t.Fatal("Shouldn't have permissions")
}
@@ -250,7 +306,7 @@ func TestGetPostCount(t *testing.T) {
Client.LoginByEmail(team.Name, user.Email, "pwd")
- if result, err := Client.GetAnalytics(team.Id, "post_counts_day"); err != nil {
+ if result, err := Client.GetTeamAnalytics(team.Id, "post_counts_day"); err != nil {
t.Fatal(err)
} else {
rows := result.Data.(model.AnalyticsRows)
@@ -284,7 +340,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
Srv.Store.(*store.SqlStore).GetMaster().Exec("UPDATE Posts SET CreateAt = :CreateAt WHERE ChannelId = :ChannelId",
map[string]interface{}{"ChannelId": channel1.Id, "CreateAt": utils.MillisFromTime(utils.Yesterday())})
- if _, err := Client.GetAnalytics(team.Id, "user_counts_with_posts_day"); err == nil {
+ if _, err := Client.GetTeamAnalytics(team.Id, "user_counts_with_posts_day"); err == nil {
t.Fatal("Shouldn't have permissions")
}
@@ -295,7 +351,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) {
Client.LoginByEmail(team.Name, user.Email, "pwd")
- if result, err := Client.GetAnalytics(team.Id, "user_counts_with_posts_day"); err != nil {
+ if result, err := Client.GetTeamAnalytics(team.Id, "user_counts_with_posts_day"); err != nil {
t.Fatal(err)
} else {
rows := result.Data.(model.AnalyticsRows)
diff --git a/model/client.go b/model/client.go
index 75b93c971..b8e7c4894 100644
--- a/model/client.go
+++ b/model/client.go
@@ -434,7 +434,7 @@ func (c *Client) TestEmail(config *Config) (*Result, *AppError) {
}
}
-func (c *Client) GetAnalytics(teamId, name string) (*Result, *AppError) {
+func (c *Client) GetTeamAnalytics(teamId, name string) (*Result, *AppError) {
if r, err := c.DoApiGet("/admin/analytics/"+teamId+"/"+name, "", ""); err != nil {
return nil, err
} else {
@@ -443,6 +443,15 @@ func (c *Client) GetAnalytics(teamId, name string) (*Result, *AppError) {
}
}
+func (c *Client) GetSystemAnalytics(name string) (*Result, *AppError) {
+ if r, err := c.DoApiGet("/admin/analytics/"+name, "", ""); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), AnalyticsRowsFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) CreateChannel(channel *Channel) (*Result, *AppError) {
if r, err := c.DoApiPost("/channels/create", channel.ToJson()); err != nil {
return nil, err
diff --git a/web/react/components/admin_console/analytics.jsx b/web/react/components/admin_console/analytics.jsx
index 8fdf538f8..70ef1ecab 100644
--- a/web/react/components/admin_console/analytics.jsx
+++ b/web/react/components/admin_console/analytics.jsx
@@ -180,7 +180,7 @@ export default class Analytics extends React.Component {
if (this.props.newlyCreatedUsers != null) {
let content;
if (this.props.newlyCreatedUsers.length === 0) {
- content = 'Loading...';
+ content = 'Loading...';
} else {
content = (
<table>
@@ -230,6 +230,7 @@ export default class Analytics extends React.Component {
return (
<div className='wrapper--fixed team_statistics'>
<h3>{'Statistics for ' + this.props.title}</h3>
+ {serverError}
<div className='row'>
{totalCount}
{postCount}
@@ -251,7 +252,6 @@ export default class Analytics extends React.Component {
}
}
-
Analytics.defaultProps = {
title: null,
channelOpenCount: null,
diff --git a/web/react/components/admin_console/system_analytics.jsx b/web/react/components/admin_console/system_analytics.jsx
index fffe7cc53..f54813a94 100644
--- a/web/react/components/admin_console/system_analytics.jsx
+++ b/web/react/components/admin_console/system_analytics.jsx
@@ -124,7 +124,7 @@ export default class SystemAnalytics extends React.Component {
);
}
- componentWillReceiveProps(newProps) {
+ componentWillReceiveProps() {
this.setState({
serverError: null,
channel_open_count: null,