Open DellanX opened 1 day ago
Hi DellanX,
Thank you for the precise and detailed description. As I understand, the goal is to test the serialization and deserialization functionality of your JsonApiEntityProvider
implementation. In the provider options, you can find the following setting:
/**
* Json api fetch interceptor if any.
*
* @type {JsonApiFetchInterceptor}
*/
jsonApiFetchInterceptor?: JsonApiFetchInterceptor;
For serialization, you can use this setting to bypass actual fetch requests and simply verify whether the serialized document objects are correct. To do this, create an entity, perform the desired operation (add, update, or remove), and use the interceptor to check if the serialized document is accurate. The library includes JSON:API types, so you can ensure type safety here.
For deserialization, you can provide a document object that the library should deserialize and then verify the resulting entities. Use the types to mock a document object. Create a response for the operation you want to test (add, update, or remove) within the interceptor, and check if the resulting entity is correct.
I hope this information is helpful. You're right - there is currently no documentation for these options in the JsonApiEntityProvider
. It would be great to add some information about this if you have time.
Is your feature request related to a problem? Please describe.
I am now at the point where I am developing unit tests for my codebase and am trying to determine the best way to determine how to unit test my Entity classes. To which, I realize there isn't any documentation for how to do so with this library. This issue is for two tasks:
Describe the solution you'd like
For me, the testing I plan to add is just a simple Serialize Deserialize validation, for this I would do:
I don't know if the infrastructure exists to interact with the TypeManager in such a way. Especially since the JsonApiEntityProvider is going to be a factor in the Serialization and Deserialization process. But I'd like to get your feedback. Again, I don't mind typing up documentation if desired.
Describe alternatives you've considered
I pretty much have testing for this at the feature level and could leave it like that. That said, I have had issues before that were caused by spelling issues or my declarators being off. It'd be nice to have a way to isolate the problems quickly.
This library already tests itself pretty well, thus the main requirement is to validate the way that I consume this library. I considered using type Metadata for this, but I think that is too low level to be useful, the tests would likely break often for changes unrelated to the application. If I did really want to work around this, I could also:
Additional context
Testing is usually a hassle that gets put off for too long (I myself a Test Engineer am guilty of this), but it is a key step in ensuring quality code. I figure most users of this library have either developed a test process for their data models or put it off on the backburner.
I also understand if this is too unrelated of an issue, it is a problem I can definitely solve on my own time. Just figured it could be helpful for future developers.