Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brorbw committed Feb 2, 2024
1 parent adf8bd4 commit ee71803
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
8 changes: 8 additions & 0 deletions spec/expectations/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

return false unless @errors.keys.include? mismatches.keys.first

@errors.keys.each do |error|
return false unless mismatches.keys.include? error
end

@errors.values.each do |error|
return false unless mismatches.values.include? error
end
Expand All @@ -37,6 +41,10 @@
return false unless @errors.values.include? mismatch
end

mismatches.keys.each do |mismatch|
return false unless @errors.keys.include? mismatch
end

true
end

Expand Down
26 changes: 15 additions & 11 deletions spec/lib/aliquot/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@
end

shared_examples 'ECv2 PaymentMethodDetails' do

context 'IntermediateSigningKeySchema' do
let(:schema) { Aliquot::Validator::IntermediateSigningKeyContract.new }
let(:key) { token['intermediateSigningKey'] }
let(:key) { token['intermediateSigningKey'] }
subject do
key
end
Expand All @@ -272,7 +271,6 @@
it 'must be valid json'

it 'must pass' do

expect(JSON.parse(key.to_json, symbolize_names: false)).to satisfy_schema(schema)
end
end
Expand Down Expand Up @@ -476,13 +474,15 @@
token
end
describe 'non-tokenized' do
let(:schema) { Aliquot::Validator::ECv1_PaymentMethodDetailsContract.new }
let(:generator) { AliquotPay.new(protocol_version: :ECv1, type: :browser) }
let(:token) { generator.token }
include_examples 'Validator Spec'

context 'pan' do
let(:schema) { Aliquot::Validator::ECv1_PaymentMethodDetailsContract.new }
let(:token) { generator.build_cleartext_message['paymentMethodDetails'] }
it 'must exist' do
token.merge!('threedsCryptogram' => token.delete('3dsCryptogram'))
token.delete('pan')
is_expected.to dissatisfy_schema(schema, {pan: ['is missing']})
end
Expand All @@ -509,13 +509,15 @@
end

describe 'tokenized' do
let(:schema) { Aliquot::Validator::ECv1_TokenizedPaymentMethodDetailsContract.new }
let(:generator) { AliquotPay.new(protocol_version: :ECv1, type: :app) }
let(:token) { generator.token }
include_examples 'Validator Spec'

context 'dpan' do
let(:schema) { Aliquot::Validator::ECv1_TokenizedPaymentMethodDetailsContract.new }
let(:token) { generator.build_cleartext_message['paymentMethodDetails'] }
it 'must exist' do
token.merge!('threedsCryptogram' => token.delete('3dsCryptogram'))
token.delete('dpan')
is_expected.to dissatisfy_schema(schema, {dpan: ['is missing']})
end
Expand All @@ -534,11 +536,10 @@

context 'intermediateSigningKey' do
let(:schema) { Aliquot::Validator::TokenContract.new }
let(:input) { token }

it 'should not be enforced' do
token.delete('intermediateSigningKey')
expect(JSON.parse(input.to_json, symbolize_names: false)).to satisfy_schema(schema)
expect(JSON.parse(token.to_json, symbolize_names: false)).to satisfy_schema(schema)
end
end
end
Expand All @@ -549,14 +550,16 @@
token
end
context 'non-tokenized' do
let(:schema) { Aliquot::Validator::ECv2_PaymentMethodDetailsContract.new }
let(:generator) { AliquotPay.new(protocol_version: :ECv2, type: :browser) }
let(:token) { generator.token }
include_examples 'Validator Spec'
include_examples 'ECv2 PaymentMethodDetails'

context 'pan' do
let(:schema) { Aliquot::Validator::ECv2_PaymentMethodDetailsContract.new }
let(:token) { generator.build_cleartext_message['paymentMethodDetails'] }
it 'must exist' do
token.merge!('threedsCryptogram' => token.delete('3dsCryptogram'))
token.delete('pan')
is_expected.to dissatisfy_schema(schema, {pan: ['is missing']})
end
Expand All @@ -572,16 +575,17 @@
end
end


context 'tokenized' do
let(:schema) { Aliquot::Validator::ECv2_TokenizedPaymentMethodDetailsContract.new }
let(:generator) { AliquotPay.new(protocol_version: :ECv2, type: :browser) }
let(:generator) { AliquotPay.new(protocol_version: :ECv2, type: :app) }
let(:token) { generator.token }
include_examples 'Validator Spec'
include_examples 'ECv2 PaymentMethodDetails'

context 'pan' do
let(:schema) { Aliquot::Validator::ECv2_TokenizedPaymentMethodDetailsContract.new }
let(:token) { generator.build_cleartext_message['paymentMethodDetails'] }
it 'must exist' do
token.merge!('threedsCryptogram' => token.delete('3dsCryptogram'))
token.delete('pan')
is_expected.to dissatisfy_schema(schema, {pan: ['is missing']})
end
Expand Down

0 comments on commit ee71803

Please sign in to comment.