🎭 📊 Anonymous Metrics V0 (#2170)
* Migrations in place, how to run them?
* Remove down migrations and touch database.go
* Database and Database Test package in place, added functions to get and store app metrics
* make generate output
* Minor bug fix on app metrics insert and select
* Add a validation layer to restrict what can be saved in the database
* Make validation more terse, throw error if schema doesn't exist, expose appmetrics service
* service updates
* Compute all errors before sending them out
* Trying to bring a closjure to appmetrics go
* Expose appmetrics via an api, skip fancy
* Address value as Jason Dawt Rawmasage to ease parsing
* Introduce a buffered chan with magic cap of 8 to minimize writes to DB. Tests for service and API. Also expose GetAppMetrics function.
* Lint issues
* Remove autoincrement, undo waku.json changes, fix error being shadowed, return nil where nil ought to be returned, get rid of buffered channel
* Bump migration number
* Fix API factory usage
* Add comment re:json.RawMessage instead of strings
* Get rid of test vars, throw save error inside the loop
* Update version
Co-authored-by: Samuel Hawksby-Robinson <samuel@samyoul.com>
2021-03-17 12:39:28 +00:00
|
|
|
package appmetrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/xeipuuv/gojsonschema"
|
|
|
|
)
|
|
|
|
|
2021-04-12 12:25:53 +00:00
|
|
|
func TestNavigateToCofxSchema(t *testing.T) {
|
|
|
|
NavigateToCofxLoader := gojsonschema.NewGoLoader(NavigateToCofxSchema)
|
|
|
|
schema, _ := gojsonschema.NewSchema(NavigateToCofxLoader)
|
🎭 📊 Anonymous Metrics V0 (#2170)
* Migrations in place, how to run them?
* Remove down migrations and touch database.go
* Database and Database Test package in place, added functions to get and store app metrics
* make generate output
* Minor bug fix on app metrics insert and select
* Add a validation layer to restrict what can be saved in the database
* Make validation more terse, throw error if schema doesn't exist, expose appmetrics service
* service updates
* Compute all errors before sending them out
* Trying to bring a closjure to appmetrics go
* Expose appmetrics via an api, skip fancy
* Address value as Jason Dawt Rawmasage to ease parsing
* Introduce a buffered chan with magic cap of 8 to minimize writes to DB. Tests for service and API. Also expose GetAppMetrics function.
* Lint issues
* Remove autoincrement, undo waku.json changes, fix error being shadowed, return nil where nil ought to be returned, get rid of buffered channel
* Bump migration number
* Fix API factory usage
* Add comment re:json.RawMessage instead of strings
* Get rid of test vars, throw save error inside the loop
* Update version
Co-authored-by: Samuel Hawksby-Robinson <samuel@samyoul.com>
2021-03-17 12:39:28 +00:00
|
|
|
|
|
|
|
// test correct json
|
2021-04-12 12:25:53 +00:00
|
|
|
validSampleVal := `{"view_id": "less-than-32", "params": {"screen": ""}}`
|
🎭 📊 Anonymous Metrics V0 (#2170)
* Migrations in place, how to run them?
* Remove down migrations and touch database.go
* Database and Database Test package in place, added functions to get and store app metrics
* make generate output
* Minor bug fix on app metrics insert and select
* Add a validation layer to restrict what can be saved in the database
* Make validation more terse, throw error if schema doesn't exist, expose appmetrics service
* service updates
* Compute all errors before sending them out
* Trying to bring a closjure to appmetrics go
* Expose appmetrics via an api, skip fancy
* Address value as Jason Dawt Rawmasage to ease parsing
* Introduce a buffered chan with magic cap of 8 to minimize writes to DB. Tests for service and API. Also expose GetAppMetrics function.
* Lint issues
* Remove autoincrement, undo waku.json changes, fix error being shadowed, return nil where nil ought to be returned, get rid of buffered channel
* Bump migration number
* Fix API factory usage
* Add comment re:json.RawMessage instead of strings
* Get rid of test vars, throw save error inside the loop
* Update version
Co-authored-by: Samuel Hawksby-Robinson <samuel@samyoul.com>
2021-03-17 12:39:28 +00:00
|
|
|
doc := gojsonschema.NewStringLoader(validSampleVal)
|
|
|
|
result, err := schema.Validate(doc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, result.Valid())
|
|
|
|
|
|
|
|
// test in-correct json
|
2021-04-12 12:25:53 +00:00
|
|
|
invalidSampleVal := `{"view_id": "more-than-32-chars-3232323232323232323232", "params": {"screen": "not-login"}}`
|
🎭 📊 Anonymous Metrics V0 (#2170)
* Migrations in place, how to run them?
* Remove down migrations and touch database.go
* Database and Database Test package in place, added functions to get and store app metrics
* make generate output
* Minor bug fix on app metrics insert and select
* Add a validation layer to restrict what can be saved in the database
* Make validation more terse, throw error if schema doesn't exist, expose appmetrics service
* service updates
* Compute all errors before sending them out
* Trying to bring a closjure to appmetrics go
* Expose appmetrics via an api, skip fancy
* Address value as Jason Dawt Rawmasage to ease parsing
* Introduce a buffered chan with magic cap of 8 to minimize writes to DB. Tests for service and API. Also expose GetAppMetrics function.
* Lint issues
* Remove autoincrement, undo waku.json changes, fix error being shadowed, return nil where nil ought to be returned, get rid of buffered channel
* Bump migration number
* Fix API factory usage
* Add comment re:json.RawMessage instead of strings
* Get rid of test vars, throw save error inside the loop
* Update version
Co-authored-by: Samuel Hawksby-Robinson <samuel@samyoul.com>
2021-03-17 12:39:28 +00:00
|
|
|
doc = gojsonschema.NewStringLoader(invalidSampleVal)
|
|
|
|
result, err = schema.Validate(doc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, result.Valid())
|
|
|
|
|
|
|
|
// test extra params
|
2021-04-12 12:25:53 +00:00
|
|
|
extraParamsVal := `{"view_id": "valid-view", "params": {"screen": "login"}, "fishy-key": "fishy-val"}`
|
🎭 📊 Anonymous Metrics V0 (#2170)
* Migrations in place, how to run them?
* Remove down migrations and touch database.go
* Database and Database Test package in place, added functions to get and store app metrics
* make generate output
* Minor bug fix on app metrics insert and select
* Add a validation layer to restrict what can be saved in the database
* Make validation more terse, throw error if schema doesn't exist, expose appmetrics service
* service updates
* Compute all errors before sending them out
* Trying to bring a closjure to appmetrics go
* Expose appmetrics via an api, skip fancy
* Address value as Jason Dawt Rawmasage to ease parsing
* Introduce a buffered chan with magic cap of 8 to minimize writes to DB. Tests for service and API. Also expose GetAppMetrics function.
* Lint issues
* Remove autoincrement, undo waku.json changes, fix error being shadowed, return nil where nil ought to be returned, get rid of buffered channel
* Bump migration number
* Fix API factory usage
* Add comment re:json.RawMessage instead of strings
* Get rid of test vars, throw save error inside the loop
* Update version
Co-authored-by: Samuel Hawksby-Robinson <samuel@samyoul.com>
2021-03-17 12:39:28 +00:00
|
|
|
doc = gojsonschema.NewStringLoader(extraParamsVal)
|
|
|
|
result, err = schema.Validate(doc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, result.Valid())
|
|
|
|
|
|
|
|
// test less params
|
|
|
|
lessParamsVal := `{"view_id": "valid-view"}`
|
|
|
|
doc = gojsonschema.NewStringLoader(lessParamsVal)
|
|
|
|
result, err = schema.Validate(doc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, result.Valid())
|
|
|
|
}
|