clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
dharrigan 2020-09-09T05:52:17.190500Z

Good Morning!

seancorfield 2020-09-09T05:58:35.190800Z

Mornin' πŸ‘‹:skin-tone-2:

dharrigan 2020-09-09T06:02:28.191Z

All good over the pond?

seancorfield 2020-09-09T06:13:36.191600Z

Aside from the firestorm burning up California and the out-of-control pandemic, yeah, I guess 😐

seancorfield 2020-09-09T06:14:09.192300Z

Roll on November 3rd. Although we likely won't know the final result for days. Maybe weeks. Argh!

dharrigan 2020-09-09T06:25:11.193Z

Oh, I'm thinking it's going to be depressing news - no matter who wins - there's a'trouble brewing methinks.

☝️ 1
mccraigmccraig 2020-09-09T08:20:19.193500Z

Β‘mawningΒ‘

dominicm 2020-09-09T08:38:52.193700Z

Morning :)

alexlynham 2020-09-09T09:40:14.193800Z

morning

thomas 2020-09-09T09:56:45.194Z

mogge

Toby Worland 2020-09-09T10:09:56.194200Z

Morning

Wes Hall 2020-09-09T11:01:09.196100Z

Hey folks, I started a new contract on Monday (back in Java land for a bit), but a recruiter I have been working with has just sent me a spec for a company looking to hire some Clojure permies. I hope I am not out of line mentioning it in here (I know there is a #jobs), but I do seem to remember a few people mentioning that they were currently on the lookout. Ping me with a DM if anybody wants an intro. Cheers.

Wes Hall 2020-09-09T11:01:57.196700Z

I should mention, I wont be asking for or taking any referral fees for this, just thought I would ask in case it helps anybody out.

2020-09-09T12:05:00.197Z

Morn'

2020-09-09T12:31:27.197200Z

Hi all, the recording of the following event is now available online: William Parker - Logic programming with clara-rules @ LNDCLJ https://youtu.be/aJbdTP5hL0U

πŸ‘ 2
2020-09-09T13:03:44.197800Z

Thanks again for organising it @bruno.bonacci πŸ˜ƒ... The talk was interesting!

2020-09-09T13:08:18.198200Z

πŸ‘

dharrigan 2020-09-09T15:50:19.199300Z

I have discovered with-redefs

dominicm 2020-09-09T16:25:40.199600Z

Undiscover it

dominicm 2020-09-09T16:25:43.199700Z

It's useless

dharrigan 2020-09-09T16:39:49.199900Z

oh

dharrigan 2020-09-09T16:40:11.200400Z

seems to do what I want, in a test, I can "mock" out a function that calls to an external API

dharrigan 2020-09-09T16:40:19.200600Z

what would you suggest otherwise?

dominicm 2020-09-09T16:43:02.200700Z

Write your functions to take the result of the external API directly.

dharrigan 2020-09-09T16:43:19.200900Z

I do

dharrigan 2020-09-09T16:43:30.201200Z

But at some point, you have to invoke something

dharrigan 2020-09-09T16:43:45.201500Z

there is an side effect somewhere

dominicm 2020-09-09T16:45:26.201700Z

Not necessarily, you will have an orchestrating function that does this:

(-> (call-external-service) a b c)
And your test will do this:
(-> some-map a b c)

dominicm 2020-09-09T16:46:16.201800Z

Instead of writing code like this:

(defn A [] (println "A") (B))
(defn B [] (println "B"))
Write this:
(defn A [] (println "A"))
(defn B [] (println "B"))

(do (A) (B))

dominicm 2020-09-09T16:46:53.201900Z

Finally, if you really must do the side effect thing, use a protocol to mock the external service and pass it around. It'll cause you way less headaches, promise. e.g. if you ever turn on parallel tests in eftest.

dharrigan 2020-09-09T16:47:30.202400Z

My function is very simple, I'll have to think how it can be rewritten, i.e.,

dharrigan 2020-09-09T16:47:38.202700Z

(defn filter-for-valid-agreement
  [policies to app-config]
  (first (filter #(ac/query-for-associations (:agreementId %) to app-config) policies)))

dharrigan 2020-09-09T16:48:19.203500Z

the ac/query-for-associations does a API lookup and returns a map or nil if an assocation is found.

dharrigan 2020-09-09T16:48:59.204100Z

so I redef'ed ac/query-for-associations to return data that I'm interested in during my test.

dharrigan 2020-09-09T16:49:12.204400Z

and tested the filter-for-valid-agreement function

dominicm 2020-09-09T16:49:45.204500Z

What property are you trying to test?

dominicm 2020-09-09T16:50:02.204600Z

I wouldn't think it too useful to test given how simple it is :)

dharrigan 2020-09-09T16:50:49.205400Z

it's important to behave the way I expect, i.e., either return the first of policy (that has an associations) or a nil result

dharrigan 2020-09-09T16:51:06.205800Z

a bug was discovered today that didn't take that into account, so I wrote a test specifically for that.

dominicm 2020-09-09T16:53:47.206100Z

https://cognitect.com/blog/2016/9/15/works-on-my-machine-understanding-var-bindings-and-roots I remember this being more scolding, but it doesn't seem to be now. But yeah, with-redefs is hard.

dharrigan 2020-09-09T16:54:17.206600Z

I'll keep that in mind and see if I can also take into account your suggestions too πŸ™‚

dharrigan 2020-09-09T16:54:19.206800Z

All very helpful

dharrigan 2020-09-09T16:55:04.207300Z

btw, i've updated my startrek projects, using aero and clip to be all the latest

dharrigan 2020-09-09T16:55:14.207600Z

I do like me some clip - it should be promoted more!

dominicm 2020-09-09T16:57:49.207900Z

Welp *scolding. Never typed this before. I assumed it was the same word.

dominicm 2020-09-09T17:01:32.208100Z

So yeah, use protocols if you're testing stateful functions. Try to pass the results of stateful functions around though instead. Avoid with-redefs always.

dharrigan 2020-09-09T17:08:54.208300Z

Will review and try πŸ™‚

dharrigan 2020-09-09T17:08:58.208500Z

Thanks once again! πŸ™‚

dominicm 2020-09-09T17:12:25.208600Z

> I do like me some clip - it should be promoted more! Promotion is not something I really know how to do :). Happy users go a long way though.

dharrigan 2020-09-09T17:18:03.208900Z

I'm happy πŸ™‚