mirror of
https://github.com/status-im/status-go.git
synced 2025-01-09 14:16:21 +00:00
2df9df10ab
interface for initializing db, which is implemented for appdatabase and walletdatabase. TBD for multiaccounts DB. Unified DB initializion for all tests using helpers and new interface. Reduced sqlcipher kdf iterations for all tests to 1.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package appmetrics
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/status-im/status-go/appdatabase"
|
|
"github.com/status-im/status-go/appmetrics"
|
|
"github.com/status-im/status-go/t/helpers"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func setupTestDB(t *testing.T) (*appmetrics.Database, func()) {
|
|
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "appmetrics-service")
|
|
require.NoError(t, err)
|
|
return appmetrics.NewDB(db), func() { require.NoError(t, cleanup()) }
|
|
}
|
|
|
|
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)
|
|
}
|