Commit e7568352 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'validate-context-schema' into 'master'

Add snowplow helper for schema match

See merge request gitlab-org/gitlab!60480
parents d45d1509 509a4899
......@@ -28,6 +28,8 @@ RSpec.describe SurveyResponsesController do
action: 'submit_response',
context: [{ schema: described_class::SURVEY_RESPONSE_SCHEMA_URL, data: { response: 'bar', survey_id: 1 } }]
)
match_snowplow_context_schema(schema_path: 'survey_response_schema', context: { response: 'bar', survey_id: 1, instance_id: 2 } )
end
end
......
{
"description": "Schema for a Gitlab survey_response event",
"self": {
"vendor": "com.gitlab",
"name": "survey_response",
"version": "1-0-0",
"format": "jsonschema"
},
"type": "object",
"additionalProperties": false,
"required": ["survey_id", "response"],
"properties": {
"survey_id": {
"description": "Survey ID",
"type": "integer",
"minimum": 0,
"maximum": 2147483647
},
"response": {
"description": "Response",
"type": "string",
"maxLength": 10000
},
"instance_id": {
"description": "Instance ID",
"type": ["integer", "null"],
"minimum": 0,
"maximum": 2147483647
},
"user_id": {
"description": "User ID",
"type": ["integer", "null"],
"minimum": 0,
"maximum": 2147483647
},
"email": {
"description": "Email",
"type": ["string", "null"],
"maxLength": 255
},
"name": {
"description": "Name",
"type": ["string", "null"],
"maxLength": 255
},
"username": {
"description": "Username",
"type": ["string", "null"],
"maxLength": 255
}
}
}
......@@ -60,6 +60,10 @@ module SnowplowHelpers
.with(category, action, **kwargs).at_least(:once)
end
def match_snowplow_context_schema(schema_path:, context:)
expect(context).to match_snowplow_schema(schema_path)
end
# Asserts that no call to `Gitlab::Tracking#event` was made.
#
# Example:
......
......@@ -45,6 +45,15 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options|
end
end
RSpec::Matchers.define :match_snowplow_schema do |schema, dir: nil, **options|
match do |data|
schema_path = Pathname.new(Rails.root.join(dir.to_s, 'spec', "fixtures/product_intelligence/#{schema}.json").to_s)
validator = SchemaPath.validator(schema_path)
validator.valid?(data.stringify_keys)
end
end
RSpec::Matchers.define :match_schema do |schema, dir: nil, **options|
match do |data|
schema = SchemaPath.expand(schema, dir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment