Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom function validation #29

Conversation

erikgustafson-klarna
Copy link

This PR allows using user defined functions for validating and reading values from JSON fields.

@andreineculau
Copy link
Member

I'm sorry but I'm going to reject this PR.
A major advantage of KATT is that the scenarios (aka blueprints) are language-abstract.

That said, you can do what you want without any change in KATT by introducing a new validation type e.g.

{
  "type": "klarna_erlang",
  "erl_eval": "some_module:some_validation_fun(arg1, arg2)"
}
KlarnaJson =
  fun(recall_body) ->
    [ fun katt_callbacks_json:recall_body/4
    ];
  fun(parse) ->
    [ fun katt_callbacks_json:parse/5
    ];
  fun(validate_body) ->
    [ fun katt_callbacks_json:validate_body/3
    ],
  fun(validate_type) ->
    [ fun katt_callbacks_json:validate_type/7
    , fun klarna_callbacks_json:validate_type/7
    ],
katt:run("klarna_erlang_scenario.apib", [], [{ext, KlarnaJson}]).

where

klarna_callbacks_json:validate_type/7 is basically like https://github.com/for-GET/katt/blob/master/src/katt_callbacks_json.erl#L98 but not for the "klarna_erlang" type, with your code from https://github.com/for-GET/katt/pull/29/files#diff-0ca8b609d9263432236ebef8184c89c0R489

@andreineculau
Copy link
Member

Out of curiousity, what type of validation are you doing in your custom funs? i.e. what validation is not supported by KATT today?

@erikgustafson-klarna
Copy link
Author

Okay,

Regards Erik

On Wed, Feb 24, 2016 at 1:12 PM, Andrei Neculau notifications@github.com
wrote:

I'm sorry but I'm going to reject this PR.
A major advantage of KATT is that the scenarios (aka blueprints) are
language-abstract.

That said, you can do what you want without any change in KATT by
introducing a new validation type e.g.

{
"type": "klarna_erlang",
"erl_eval": "some_module:some_validation_fun(arg1, arg2)"
}

KlarnaJson =
fun(recall_body) ->
[ fun katt_callbacks_json:recall_body/4
];
fun(parse) ->
[ fun katt_callbacks_json:parse/5
];
fun(validate_body) ->
[ fun katt_callbacks_json:validate_body/3
],
fun(validate_type) ->
[ fun katt_callbacks_json:validate_type/7
, fun klarna_callbacks_json:validate_type/7
],katt:run("klarna_erlang_scenario.apib", [], [{ext, KlarnaJson}]).

where

klarna_callbacks_json:validate_type/7 is basically like
https://github.com/for-GET/katt/blob/master/src/katt_callbacks_json.erl#L98
but not for the "klarna_erlang" type, with your code from
https://github.com/for-GET/katt/pull/29/files#diff-0ca8b609d9263432236ebef8184c89c0R489


Reply to this email directly or view it on GitHub
#29 (comment).

@erikgustafson-klarna
Copy link
Author

There are 3 things we need to do

  1. Making sure that a list contains at least some elements regardless of
    order.
  2. Making sure that a JSON structure like this one

[
{type:"elv"},
{type:"invoice"},
.....
]

contains at least elements with type elv and invoice. Order in this case is
unknown and extra elements could be present

  1. Using regex to pick out values from a string to store for use further
    down in the test

// Erik

On Wed, Feb 24, 2016 at 1:14 PM, Andrei Neculau notifications@github.com
wrote:

Out of curiousity, what type of validation are you doing in your custom
funs? i.e. what validation is not supported by KATT today?


Reply to this email directly or view it on GitHub
#29 (comment).

@andreineculau
Copy link
Member

  1. Already supported, that's why we introduced the "set" validation type e.g. https://github.com/for-GET/katt/blob/master/test/katt_run_validate_type_set_tests.erl#L162
  2. don't see how this is different than 1. All structures accept unknown elements, unless {{unexpected}} is given.
  3. also already supported https://github.com/for-GET/katt/blob/master/test/katt_run_tests.erl#L449

@erikgustafson-klarna
Copy link
Author

Cool, we are still running on a pretty old version of katt internally in
Klarna and the set feature was not included in that

Thanks for your time

On Wed, Feb 24, 2016 at 1:45 PM, Andrei Neculau notifications@github.com
wrote:

Already supported, that's why we introduced the "set" validation type
e.g.
https://github.com/for-GET/katt/blob/master/test/katt_run_validate_type_set_tests.erl#L162
2.

don't see how this is different than 1. All structures accept unknown
elements, unless {{unexpected}} is given.
3.

also already supported
https://github.com/for-GET/katt/blob/master/test/katt_run_tests.erl#L449


Reply to this email directly or view it on GitHub
#29 (comment).

@sstrigler
Copy link

This use case rings a bell, a thing I wanted to take care of a while ago. :(

@sstrigler
Copy link

Ah m)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants