import { HttpApiBuilder, HttpApiClient, HttpClient } from '@effect/platform'
import { NodeHttpServer } from '@effect/platform-node'
// Test setup with mocked JWT middleware
const TestJwt = Layer.succeed(JwtSpec, {
bearer: (token: Redacted.Redacted<string>) =>
Effect.succeed({
jwtPayload: new JWTPayload({ /* ... */ }),
jwtRawToken: token,
}),
})
const LayerTest = HttpGroupTest(
GroupApiSpec,
GroupProtectedLive.pipe(
Layer.provide(TestJwt),
Layer.provide(TestConfigProvider),
),
)
describe('Protected Route', () => {
// ❌ IT DOES NOT WORK
it.effect('should fail without authorization header', () =>
Effect.gen(function* () {
const client = yield* HttpApiClient.make(GroupApiSpec)
const error = yield* client.Protected.test().pipe(Effect.flip)
expect(error).toEqual(
expect.objectContaining({ _tag: 'HttpApiError', status: 403 })
)
}).pipe(Effect.provide(LayerTest))
)
import { HttpApiBuilder, HttpApiClient, HttpClient } from '@effect/platform'
import { NodeHttpServer } from '@effect/platform-node'
// Test setup with mocked JWT middleware
const TestJwt = Layer.succeed(JwtSpec, {
bearer: (token: Redacted.Redacted<string>) =>
Effect.succeed({
jwtPayload: new JWTPayload({ /* ... */ }),
jwtRawToken: token,
}),
})
const LayerTest = HttpGroupTest(
GroupApiSpec,
GroupProtectedLive.pipe(
Layer.provide(TestJwt),
Layer.provide(TestConfigProvider),
),
)
describe('Protected Route', () => {
// ❌ IT DOES NOT WORK
it.effect('should fail without authorization header', () =>
Effect.gen(function* () {
const client = yield* HttpApiClient.make(GroupApiSpec)
const error = yield* client.Protected.test().pipe(Effect.flip)
expect(error).toEqual(
expect.objectContaining({ _tag: 'HttpApiError', status: 403 })
)
}).pipe(Effect.provide(LayerTest))
)