UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

266 lines 11.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const service_1 = require("../vo/service"); describe('Service Value Object', () => { describe('DefaultServiceConfig', () => { it('should have correct default values', () => { expect(service_1.DefaultServiceConfig.disqus.disable).toBe(false); expect(service_1.DefaultServiceConfig.disqus.shortname).toBe(''); expect(service_1.DefaultServiceConfig.googleAnalytics.disable).toBe(false); expect(service_1.DefaultServiceConfig.googleAnalytics.respectDoNotTrack).toBe(false); expect(service_1.DefaultServiceConfig.googleAnalytics.id).toBe(''); expect(service_1.DefaultServiceConfig.rss.limit).toBe(0); }); }); describe('decodeServiceConfig', () => { it('should decode empty data with default values', () => { const config = (0, service_1.decodeServiceConfig)({}); expect(config.disqus.disable).toBe(false); expect(config.disqus.shortname).toBe(''); expect(config.googleAnalytics.disable).toBe(false); expect(config.googleAnalytics.respectDoNotTrack).toBe(false); expect(config.googleAnalytics.id).toBe(''); expect(config.rss.limit).toBe(0); }); it('should decode privacy settings', () => { const inputData = { privacy: { disqus: { disable: true }, googleAnalytics: { disable: true, respectDoNotTrack: true } } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.disqus.disable).toBe(true); expect(config.googleAnalytics.disable).toBe(true); expect(config.googleAnalytics.respectDoNotTrack).toBe(true); }); it('should decode services settings', () => { const inputData = { services: { disqus: { shortname: 'my-blog' }, googleAnalytics: { id: 'GA-123456789' }, rss: { limit: 20 } } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.disqus.shortname).toBe('my-blog'); expect(config.googleAnalytics.id).toBe('GA-123456789'); expect(config.rss.limit).toBe(20); }); it('should handle mixed privacy and services settings', () => { const inputData = { privacy: { disqus: { disable: true }, googleAnalytics: { respectDoNotTrack: true } }, services: { disqus: { shortname: 'disabled-blog' }, googleAnalytics: { id: 'GA-987654321' }, rss: { limit: 50 } } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.disqus.disable).toBe(true); expect(config.disqus.shortname).toBe('disabled-blog'); expect(config.googleAnalytics.disable).toBe(false); // not set in privacy expect(config.googleAnalytics.respectDoNotTrack).toBe(true); expect(config.googleAnalytics.id).toBe('GA-987654321'); expect(config.rss.limit).toBe(50); }); it('should handle backwards compatibility settings', () => { const inputData = { googleanalytics: 'GA-OLD-FORMAT', disqusshortname: 'old-shortname', rssLimit: 15 }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.googleAnalytics.id).toBe('GA-OLD-FORMAT'); expect(config.disqus.shortname).toBe('old-shortname'); expect(config.rss.limit).toBe(15); }); it('should prioritize new format over backwards compatibility', () => { const inputData = { services: { googleAnalytics: { id: 'GA-NEW-FORMAT' }, disqus: { shortname: 'new-shortname' }, rss: { limit: 25 } }, // These should be ignored in favor of services config googleanalytics: 'GA-OLD-FORMAT', disqusshortname: 'old-shortname', rssLimit: 15 }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.googleAnalytics.id).toBe('GA-NEW-FORMAT'); expect(config.disqus.shortname).toBe('new-shortname'); expect(config.rss.limit).toBe(25); }); it('should handle partial privacy settings', () => { const inputData = { privacy: { disqus: { disable: true } // googleAnalytics not specified } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.disqus.disable).toBe(true); expect(config.googleAnalytics.disable).toBe(false); // default expect(config.googleAnalytics.respectDoNotTrack).toBe(false); // default }); it('should handle partial services settings', () => { const inputData = { services: { disqus: { shortname: 'partial-blog' } // googleAnalytics and rss not specified } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.disqus.shortname).toBe('partial-blog'); expect(config.googleAnalytics.id).toBe(''); // default expect(config.rss.limit).toBe(0); // default }); it('should handle boolean values correctly', () => { const falseData = { privacy: { disqus: { disable: false }, googleAnalytics: { disable: false, respectDoNotTrack: false } } }; const falseConfig = (0, service_1.decodeServiceConfig)(falseData); expect(falseConfig.disqus.disable).toBe(false); expect(falseConfig.googleAnalytics.disable).toBe(false); expect(falseConfig.googleAnalytics.respectDoNotTrack).toBe(false); const trueData = { privacy: { disqus: { disable: true }, googleAnalytics: { disable: true, respectDoNotTrack: true } } }; const trueConfig = (0, service_1.decodeServiceConfig)(trueData); expect(trueConfig.disqus.disable).toBe(true); expect(trueConfig.googleAnalytics.disable).toBe(true); expect(trueConfig.googleAnalytics.respectDoNotTrack).toBe(true); }); it('should handle zero RSS limit correctly', () => { const inputData = { services: { rss: { limit: 0 } } }; const config = (0, service_1.decodeServiceConfig)(inputData); expect(config.rss.limit).toBe(0); }); it('should handle undefined and null values gracefully', () => { const inputData = { privacy: { disqus: { disable: undefined }, googleAnalytics: { disable: null, respectDoNotTrack: undefined } }, services: { disqus: { shortname: null }, googleAnalytics: { id: undefined }, rss: { limit: null } } }; const config = (0, service_1.decodeServiceConfig)(inputData); // Undefined/null boolean values: null is passed through in ternary logic expect(config.disqus.disable).toBe(false); // defaults to false expect(config.googleAnalytics.disable).toBe(null); // null is passed through expect(config.googleAnalytics.respectDoNotTrack).toBe(false); // defaults to false // Null/undefined string values should use defaults expect(config.disqus.shortname).toBe(''); expect(config.googleAnalytics.id).toBe(''); // Null number values: null is passed through in ternary logic expect(config.rss.limit).toBe(null); }); it('should handle complex real-world configuration', () => { const realWorldData = { privacy: { disqus: { disable: false }, googleAnalytics: { disable: false, respectDoNotTrack: true } }, services: { disqus: { shortname: 'my-awesome-blog' }, googleAnalytics: { id: 'GA-4-ABCDEFGHIJ' }, rss: { limit: 10 } }, // Legacy settings (should be ignored) googleanalytics: 'GA-OLD-123', disqusshortname: 'old-name' }; const config = (0, service_1.decodeServiceConfig)(realWorldData); expect(config.disqus.disable).toBe(false); expect(config.disqus.shortname).toBe('my-awesome-blog'); expect(config.googleAnalytics.disable).toBe(false); expect(config.googleAnalytics.respectDoNotTrack).toBe(true); expect(config.googleAnalytics.id).toBe('GA-4-ABCDEFGHIJ'); expect(config.rss.limit).toBe(10); }); }); }); //# sourceMappingURL=vo-service.test.js.map