I have written some code in Clojure that produces Datomic transaction data, and I'd like to write some tests to check that the data is created as expected.
Essentially, I need to be able to demonstrate that with respect to transaction data:
[{:db/id (d/tempid :db.part/user}
:some-field "Bob"}]
=
[{:db/id (d/tempid :db.part/user}
:some-field "Bob"}]
and
[{:db/id (d/tempid :db.part/user -1}
:some-field "Bob"}]
=
[{:db/id (d/tempid :db.part/user -1}
:some-field "Bob"}]
but
[{:db/id (d/tempid :db.part/user -1}
:some-field "Bob"}]
!=
[{:db/id (d/tempid :db.part/user -2}
:some-field "Bob"}]
However, I cannot simply compare the output with an expected value as I will never know the exact DbId created until it's produced by the code, and the result is different every time (d/tempid ...) is run anyway. So equality checks will return false.
Does anyone have any thoughts for the best way to do this in a general way, so it can be run against any sort of transaction data (e.g. works with nested transaction data)?
I have considered creating my own MockDbId type, and then redefining (d/tempid ...) in tests so I have more control, but it doesn't feel like a good way to achieve the desired behaviour.
Any advice would be greatly appreciated.
Thanks,
Matt.
Aucun commentaire:
Enregistrer un commentaire