UNPKG

qapinterface

Version:

Comprehensive API utilities for Node.js applications including authentication, security, request processing, and response handling with zero external dependencies

59 lines (48 loc) 1.96 kB
/** * Test suite for url utilities - Mocha-style structure * Can be run with: node lib/__tests__/url.test.js */ const { createUrlSchema } = require('../url/schema-creator'); const { buildUrl } = require('../url/builder'); const TestRunner = require('./TestRunner'); const test = new TestRunner(); test.describe('URL Utilities', () => { test.describe('createUrlSchema', () => { const schema = createUrlSchema({ allowedDomains: ['example.com', 'test.com'], blockedDomains: ['blocked.com'], requireHttps: true, }); test.it('should validate a correct URL', () => { const result = schema.safeParse('https://example.com/path'); test.expect(result.success).to.be.true; }); test.it('should invalidate a URL with the wrong protocol', () => { const result = schema.safeParse('http://example.com/path'); test.expect(result.success).to.be.false; }); test.it('should invalidate a URL with a non-allowed domain', () => { const result = schema.safeParse('https://notallowed.com/path'); test.expect(result.success).to.be.false; }); test.it('should invalidate a URL with a blocked domain', () => { const result = schema.safeParse('https://blocked.com/path'); test.expect(result.success).to.be.false; }); }); test.describe('buildUrl', () => { test.it('should build a URL with an endpoint and query parameters', () => { const url = buildUrl('https://example.com', 'api/v1/users', { id: 123, format: 'json' }); test.expect(url).to.equal('https://example.com/api/v1/users?id=123&format=json'); }); test.it('should handle a base URL with a trailing slash', () => { const url = buildUrl('https://example.com/', 'api/v1/users'); test.expect(url).to.equal('https://example.com/api/v1/users'); }); }); }); (async () => { await test.run(); const success = test.summary(); process.exit(success ? 0 : 1); })();