softwaremill / softwaremill/tapir

Testing Server Sent Events

Open
#2,607 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

Hello,

I have a bunch of plain http server endpoints which works fine but one of them I needed to change to give back serverSentEventsBody so this is the only endpoint that gives back Stream[Throwable, ServerSentEvent].
I am using ZIO 2 and so I am using ZStream in the implementation.
Now when we test the endpoints we use the entire list of routes:
val wsRoutes = Router("/" -> allRoutes).orNotFound
In a similar way:

type RouteTestType[A] = ZIO[ZServer.Env, Throwable, A]
for {
            req         <- ZIO.succeed(
                             getRequest[RouteTestType](
                               Method.PATCH,
                               s"/v1/projects/pause/$Project1",
                               Some(testNewAdminContext)
                             )
                           )
            result    <- wsRoutes.run(req)
} yield assert(result)(assertionFunctions)

I did not find a way to transform the result: Response[ZIO[Server,Throwable,_]] to a ZStream to test the server sent events.
Is there a way to do it?
I could not find a solution anywhere.
If there is, sorry for raising a ticket for it. If not, will you add this feature to tapir?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the route test from wsRoutes.run(req) and the Response[ZIO[Server,Throwable,_]] result, then inspect how serverSentEventsBody and ZStream are represented in the testing APIs. Done means establishing whether the response can expose a stream for assertions, or documenting and implementing the missing SSE testing support.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
api, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.