mcp-auth-guard.module.spec.tsβ’1.81 kB
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { Test, TestingModule } from '@nestjs/testing'
import { ConfigService } from '@nestjs/config'
import { McpAuthGuardModule } from './mcp-auth-guard.module'
import { AllowlistService } from './allowlist.service'
import { EmailAllowlistGuard } from './email-allowlist.guard'
describe('McpAuthGuardModule', () => {
let module: TestingModule
let consoleWarnSpy: ReturnType<typeof vi.spyOn>
beforeEach(async () => {
// Suppress console.warn for tests that intentionally use empty email lists
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
module = await Test.createTestingModule({
imports: [McpAuthGuardModule],
providers: [
{
provide: ConfigService,
useValue: {
get: vi.fn().mockReturnValue('test@example.com'),
},
},
],
}).compile()
})
afterEach(() => {
consoleWarnSpy.mockRestore()
})
it('should be defined', () => {
expect(module).toBeDefined()
})
it('should provide AllowlistService', () => {
const service = module.get<AllowlistService>(AllowlistService)
expect(service).toBeDefined()
expect(service).toBeInstanceOf(AllowlistService)
})
it('should provide EmailAllowlistGuard', () => {
const guard = module.get<EmailAllowlistGuard>(EmailAllowlistGuard)
expect(guard).toBeDefined()
expect(guard).toBeInstanceOf(EmailAllowlistGuard)
})
it('should export AllowlistService', () => {
const service = module.get<AllowlistService>(AllowlistService)
expect(service).toBeDefined()
})
it('should export EmailAllowlistGuard', () => {
const guard = module.get<EmailAllowlistGuard>(EmailAllowlistGuard)
expect(guard).toBeDefined()
})
})