neighbour-hoods / sensemaker-lite

11 stars 1 forks source link

write tests for `SensemakerStore` #72

Closed weswalla closed 9 months ago

weswalla commented 10 months ago

In addition to having test coverage of the zome functions, we should have test coverage of the SensemakerStore by checking that it makes the right zome calls, updates the svelte stores properly, and derived store subscriptions are notified of changes in the correct way.

I know there are some tests in https://github.com/neighbour-hoods/sensemaker-lite/pull/41 which may be helpful.

weswalla commented 10 months ago

would build off of: https://github.com/neighbour-hoods/sensemaker-lite/issues/66

adaburrows commented 10 months ago

To make this more plausible we just need to inject the SensemakerService into the store instead of letting the store create it. Then we can ensure it's making the right calls in code review. Because the way things should be written, that's tantamount to proofreading for typos to make sure we're calling the right method on the SensemakerService.

We just need to separate out any complicated code from the store into a separate object or library of functions that does all the logic and uses the injected service component. That way we don't really have to check the wiring between objects in the store, unless something is truly going wrong and there's a typo somewhere. We just need to test the library of functions/object that provides the logic.

Also, since we do nothing interesting with the SensemakerService except wrap every call with the same structure, we could easily create a proxy that constructs the right call. But that could make things more error prone, since autocomplete won't work. We just need to make sure the exact same spelling is there between the zome and the client code that uses the SensemakerService. In some ways, it would be great to have some tooling that parses the Rust code and generates the TypeScript wrapper for the SensemakerService.

Just to be clear, our store will become a fairly hollow wrapper for the functions that we test. Testing anything else would be equivalent to spell checking (which our IDEs provide) and writing tests for the Svelte stores (which is Svelte's job).