Skip to content

TestClient generated using NodeTesting requires body, path, query, params as any #645

@arijoon

Description

@arijoon

Example:

import { HttpServerRequest } from '@effect/platform'
import { Schema } from '@effect/schema'
import { Effect, flow, pipe } from 'effect'
import { Api, RouterBuilder, Security } from 'effect-http'
import { NodeTesting } from 'effect-http-node'

const AuthorizationSchema = Schema.Struct({ authorization: Schema.String })
export const authHeader = Security.make(
  pipe(
    HttpServerRequest.schemaHeaders(
      AuthorizationSchema,
    ),
  ),
  {
    myApiKey: {
      name: 'Authorization',
      type: 'apiKey',
      in: 'header',
      description: 'signed authorization token',
    },
  },
)

export const addAuthHeader = Api.setRequestHeaders(
  AuthorizationSchema,
)

export const addAuth = flow(
  Api.setSecurity(authHeader),
  addAuthHeader,
)

const testApi = Api.make().pipe(
  Api.addEndpoint(
    pipe(
      Api.get('test', '/test'),
      Api.setResponseBody(Schema.String),
      addAuth,
    ),
  ),
)

const app = RouterBuilder.make(testApi).pipe(
  RouterBuilder.handle(
    'test',
    _ => Effect.succeed('ok'),
  ),
  RouterBuilder.build,
)

const testClient = NodeTesting.make(app, testApi)

// Using the client:
Effect
  .gen(function*() {
    const client = yield* testClient
    const result = yield* client.test({
      headers: { authorization: 'somevalue' },
      body: undefined,
      query: undefined,
      path: undefined,
    })
  })

Seems like extra props in type show as any. Since they are not defined on the spec, they shouldn't be allowed
image

Updated the code, it seems to come from the flow based addition of security

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions