Fork me on GitHub
#etaoin
<
2023-04-23
>
pppaul16:04:22

does anyone have a good strategy for dealing with hidden server state in your tests? eg: my resource sends an email, i need to know about a link in that email, how does your test end up with that information? do you have your tests digging in the db, or do you expose your state in a way the frontend can access it?

lread18:04:41

@U0LAJQLQ1, I think it depends on what kind of testing you want to do. If you need to know your system sent an actual email, you could wait for and parse out the link from that email from an SMTP server (fake server or otherwise). But if you trust that your email content/sending works, you could ask some internal back-end service for the link (or dig it out of some hidden spot in an HTML response). I don't think there is anything Etaoin specific about this question though, so you might get more responses if you re-ask it in #C08LK2DH7.

igrishaev06:04:07

I've been in such a situation. We used a fake SMTP server written in Golang. You can make it a part of your docker-compose or run as a binary. It accepts emails via SMTP and can return them via HTTP Api.

igrishaev06:04:37

So the pipeline was simple: in the config, you point SMTP to localhost/8025. Then you send an email with a magic link. The base-url of that link must be localhost:8080 (or another port your HTTP server runs on). Then you call the fake server's API to get the last email, parse it and get that link. Then you navigate the browser with Etaoin to that URL.

pppaul16:04:44

@U1WAUKQ3E that seems a bit extreme, my mock emails just print out to the console right now. my problem is similar, getting the links in the email. i'm exposing them to the frontend in dev mode via a redirect query params. i feel a bit uncomfortable doing this, though. so, i'm in the context where my e2e is still pure (only using the web browser, but also there are some hacks in the webpage that a normal user wouldn't have). i'm just wondering if this is too weird and if i should just be accessing my DB for these types of hidden states?

igrishaev19:04:43

well, I believe reaching the database during the test is OK; that's much simpler than a fake SMTP server. Btw, there is another approach with fake components. If you use Component or Integrant, you can pass a fake component that saves an email into a hidden atom. Then you can reach that atom in your tests.

lread20:04:08

@U0LAJQLQ1, there is no one right answer here. Like everything you just have to weigh the trade-offs and choose a path.

pppaul20:04:48

@UE21H2HHD i understand, but i do expect there to be some patterns in doing something like this, just as there are general programming patterns. 🙂

👍 2