aries-vcx icon indicating copy to clipboard operation
aries-vcx copied to clipboard

Use static JSON in messages crate tests

Open bobozaur opened this issue 1 year ago • 7 comments

Some corners were cut when developing the tests for the messages crate during its refactor in the sense that the JSON was being composed off of already tested structs or fields.

It would be better to use plain text JSON to ensure that any API change won't slip by the testing suite.

bobozaur avatar May 02 '23 10:05 bobozaur

@bobozaur i would like to work on this issue can you help me navigate it in the project directory Thank You.

SumantxD avatar May 05 '23 15:05 SumantxD

@bobozaur i would like to work on this issue can you help me navigate it in the project directory Thank You.

Not sure what you mean. This is about most tests in msg_fields module (might be others in other modules).

The ones about msg_type deserialization are fine, but the tests that are about deserializing an actual message with fields should ideally use static messages instead of serializing certain types to avoid the situation where both the serialization and the deserialization are incorrect and thus the test passes but the result is incorrect.

bobozaur avatar May 08 '23 09:05 bobozaur

I would like to try this out.

tech-bash avatar May 22 '23 13:05 tech-bash

I would like to try this out.

Have at it :). Let me know if you need more information. The overall goal is simple: to replace json in tests with static JSON strings (or just static strings wrapped in the json!() macro).

As an example:

        let expected = json!({
            "credentials~attach": content.credentials_attach,
            "~thread": decorators.thread
        });

Would become something like:

        let expected = json!({
            "credentials~attach": {
                "field1": "value1",
                "field2": "value2",
            },
            "~thread": {
                "field_1": "value1",
                "field_2": "value2",
            }
        });

This way, if the inner structure of say, the Thread type changes in a breaking way, we'd be more aware and the tests aren't going to just pass, as right now we're deserializing something we just serialized.

bobozaur avatar May 22 '23 14:05 bobozaur

Alright, thanks for the explanation!

tech-bash avatar May 22 '23 20:05 tech-bash

In the above example you have set ~thread to two same names i.e field1 so is there any specific reason behind it or as I am thinking that, the other value could be field2 as well!

tech-bash avatar Jun 01 '23 08:06 tech-bash

In the above example you have set ~thread to two same names i.e field1 so is there any specific reason behind it or as I am thinking that, the other value could be field2 as well!

Ah, my bad. Edited. They are supposed to be different fields, yes.

bobozaur avatar Jun 01 '23 11:06 bobozaur