60 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { tap, expect } from '@push.rocks/tapbundle';
 | |
| import { SmartAcme, MemoryCertManager } from '../ts/index.js';
 | |
| import { Cert } from '../ts/index.js';
 | |
| import type { IChallengeHandler } from '../ts/handlers/IChallengeHandler.js';
 | |
| 
 | |
| // Dummy handler for testing
 | |
| class DummyHandler implements IChallengeHandler<any> {
 | |
|   getSupportedTypes(): string[] { return ['dns-01']; }
 | |
|   async prepare(_: any): Promise<void> { /* no-op */ }
 | |
|   async cleanup(_: any): Promise<void> { /* no-op */ }
 | |
| }
 | |
| 
 | |
| tap.test('constructor throws without challengeHandlers', async () => {
 | |
|   expect(() => new SmartAcme({
 | |
|     accountEmail: 'test@example.com',
 | |
|     certManager: new MemoryCertManager(),
 | |
|     environment: 'integration',
 | |
|     retryOptions: {},
 | |
|   } as any)).toThrow();
 | |
| });
 | |
| 
 | |
| tap.test('constructor accepts valid challengeHandlers', async () => {
 | |
|   const sa = new SmartAcme({
 | |
|     accountEmail: 'test@example.com',
 | |
|     certManager: new MemoryCertManager(),
 | |
|     environment: 'integration',
 | |
|     retryOptions: {},
 | |
|     challengeHandlers: [new DummyHandler()],
 | |
|   });
 | |
|   expect(sa).toBeInstanceOf(SmartAcme);
 | |
| });
 | |
| // Wildcard certificate stub for integration mode (unit test override)
 | |
| tap.test('get wildcard certificate stub in integration mode', async () => {
 | |
|   // Temporarily stub SmartAcme.start and getCertificateForDomain for wildcard
 | |
|   const origStart = SmartAcme.prototype.start;
 | |
|   const origGetCert = SmartAcme.prototype.getCertificateForDomain;
 | |
|   try {
 | |
|     SmartAcme.prototype.start = async function(): Promise<void> { /* no-op */ };
 | |
|     SmartAcme.prototype.getCertificateForDomain = async function(domain: string) {
 | |
|       return new Cert({ domainName: domain });
 | |
|     };
 | |
|     const sa = new SmartAcme({
 | |
|       accountEmail: 'domains@lossless.org',
 | |
|       certManager: new MemoryCertManager(),
 | |
|       environment: 'integration',
 | |
|       retryOptions: {},
 | |
|       challengeHandlers: [new DummyHandler()],
 | |
|     });
 | |
|     await sa.start();
 | |
|     const domainWildcard = '*.example.com';
 | |
|     const cert = await sa.getCertificateForDomain(domainWildcard);
 | |
|     expect(cert.domainName).toEqual(domainWildcard);
 | |
|     await sa.stop();
 | |
|   } finally {
 | |
|     SmartAcme.prototype.start = origStart;
 | |
|     SmartAcme.prototype.getCertificateForDomain = origGetCert;
 | |
|   }
 | |
| });
 | |
| 
 | |
| export default tap.start(); |