Effect CommunityEC
Effect Community7mo ago
3 replies
mufraggihugo

HttpGroup unit testing

Hello dear community,

Would someone be kind enough to give me a hand with unit testing?

I'm trying to write unit tests for my groupHttp API, specifically for this HttpApiGroupPokemon, but I'm not getting very far...

export class HttpApiGroupPokemon extends HttpApiGroup.make("pokemon")
  .add(
    HttpApiEndpoint.get("getById", "/:id")
      .setPath(Schema.Struct({ id: Schema.NumberFromString }))
      .addSuccess(Pokemon).addError(HttpApiError.NotFound)
  )
  .add(
    HttpApiEndpoint.get("getAll", "/")
      .addSuccess(PokemonList).addError(HttpApiError.InternalServerError)
  )
  .prefix("/pokemon")
{}


export const HttpApiGroupPokemonLive = (api: ApiType) =>
  HttpApiBuilder.group(
    api,
    "pokemon",
    (handlers) =>
      Effect.gen(function*() {
        yield* Effect.logDebug("PokemonGroupLive in memory")
        const pokemonService = yield* PokemonService
        return handlers
          .handle("getById", ({ path }) => pokemonService.getById(path.id))
          .handle("getAll", (_) => pokemonService.list())
      })
  )


I feel like my implementation might go against how effect is meant to be composed.

To initialize HttpApiGroupPokemonLive, I need an API with the type of:

export class Api extends HttpApi.make("api")
  .add(HealthGroup)
  .add(HttpApiGroupPokemon)
{}


From what I understand, that means that the more groups I have, the more I’ll have to include them in my unit tests as well.

Anyway, I’m a bit stuck 😅 If anyone has docs, examples or tips on how to unit test this kind of setup, I’d really appreciate it!
Was this page helpful?