Shivek Khurana 79bf90e990
👮🏽‍♂️ Update validators and add a new event (#2189)
* Add extra event to capture other type of navigations, allow empty screen name, rename cofx to get rid of clj ns, update tests

* Some view ids are greater than 16 characters. Made it 32 to be safe.

* Tab navigation events occur outside nav, add a new validator for them

* Remove navigate to cofx event, capture screens on will focus, get rid of enum and make valid screens a string less than 32 characters

* Run make generate

* Fix test

* Bump version to 0.75.1
2021-04-12 17:55:53 +05:30

50 lines
1.3 KiB
Go

package appmetrics
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"testing"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/appmetrics"
"github.com/stretchr/testify/require"
)
func setupTestDB(t *testing.T) (*appmetrics.Database, func()) {
tmpfile, err := ioutil.TempFile("", "appmetrics-service")
require.NoError(t, err)
db, err := appdatabase.InitializeDB(tmpfile.Name(), "appmetrics-tests")
require.NoError(t, err)
return appmetrics.NewDB(db), func() {
require.NoError(t, db.Close())
require.NoError(t, os.Remove(tmpfile.Name()))
}
}
func TestValidateAppMetrics(t *testing.T) {
db, close := setupTestDB(t)
defer close()
api := NewAPI(db)
validMetrics := []appmetrics.AppMetric{appmetrics.AppMetric{
Event: "navigate-to",
Value: json.RawMessage(`{"view_id": "some-view-id", "params": {"screen": "login"}}`),
AppVersion: "1.12",
OS: "android"}}
invalidMetrics := []appmetrics.AppMetric{appmetrics.AppMetric{
Event: "navigate-to",
Value: json.RawMessage("{}"),
AppVersion: "1.12",
OS: "android"}}
err := api.ValidateAppMetrics(context.Background(), validMetrics)
require.NoError(t, err)
err = api.ValidateAppMetrics(context.Background(), invalidMetrics)
require.Error(t, err)
}