Commit 4bf5ff00 authored by Rajendra Kadam's avatar Rajendra Kadam

Add snowplow helper for schema match

Add matcher for snowplow context schema assertion
parent d91fc31a
...@@ -60,6 +60,10 @@ module SnowplowHelpers ...@@ -60,6 +60,10 @@ module SnowplowHelpers
.with(category, action, **kwargs).at_least(:once) .with(category, action, **kwargs).at_least(:once)
end 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. # Asserts that no call to `Gitlab::Tracking#event` was made.
# #
# Example: # Example:
......
...@@ -45,6 +45,17 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options| ...@@ -45,6 +45,17 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options|
end end
end end
RSpec::Matchers.define :match_snowplow_schema do |schema, dir: nil, **options|
match do |response|
schema_path = Pathname.new(SchemaPath.expand(schema, dir))
validator = SchemaPath.validator(schema_path)
data = Gitlab::Json.parse(response.body)
validator.valid?(data)
end
end
RSpec::Matchers.define :match_schema do |schema, dir: nil, **options| RSpec::Matchers.define :match_schema do |schema, dir: nil, **options|
match do |data| match do |data|
schema = SchemaPath.expand(schema, dir) 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