@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
267 lines • 9.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const module_1 = require("../vo/module");
describe('Module Value Object', () => {
describe('EmptyModuleConfig', () => {
it('should have empty arrays for mounts and imports', () => {
expect(module_1.EmptyModuleConfig.mounts).toEqual([]);
expect(module_1.EmptyModuleConfig.imports).toEqual([]);
});
});
describe('decodeModuleConfig', () => {
it('should decode empty data with default values', () => {
const config = (0, module_1.decodeModuleConfig)({});
expect(config.mounts).toEqual([]);
expect(config.imports).toEqual([]);
});
it('should decode mounts configuration', () => {
const inputData = {
mounts: [
{
source: 'content',
target: 'content'
},
{
source: 'static',
target: 'static',
lang: 'en'
}
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.mounts).toHaveLength(2);
expect(config.mounts[0]).toEqual({
source: 'content',
target: 'content',
lang: undefined
});
expect(config.mounts[1]).toEqual({
source: 'static',
target: 'static',
lang: 'en'
});
});
it('should decode imports configuration', () => {
const inputData = {
imports: [
{
path: 'github.com/user/theme',
version: 'v1.0.0'
},
{
path: 'local-module',
url: 'https://github.com/user/module.git',
version: 'main',
mounts: [
{
source: 'assets',
target: 'assets'
}
]
}
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.imports).toHaveLength(2);
expect(config.imports[0]).toEqual({
path: 'github.com/user/theme',
url: undefined,
version: 'v1.0.0',
mounts: []
});
expect(config.imports[1]).toEqual({
path: 'local-module',
url: 'https://github.com/user/module.git',
version: 'main',
mounts: [
{
source: 'assets',
target: 'assets'
}
]
});
});
it('should handle mixed mounts and imports', () => {
const inputData = {
mounts: [
{
source: 'content',
target: 'content'
}
],
imports: [
{
path: 'theme-module',
version: 'v2.0.0'
}
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.mounts).toHaveLength(1);
expect(config.imports).toHaveLength(1);
expect(config.mounts[0].source).toBe('content');
expect(config.imports[0].path).toBe('theme-module');
});
it('should handle incomplete mount data', () => {
const inputData = {
mounts: [
{
source: 'content'
// missing target
},
{
target: 'static'
// missing source
},
{} // empty mount
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.mounts).toHaveLength(3);
expect(config.mounts[0]).toEqual({
source: 'content',
target: '',
lang: undefined
});
expect(config.mounts[1]).toEqual({
source: '',
target: 'static',
lang: undefined
});
expect(config.mounts[2]).toEqual({
source: '',
target: '',
lang: undefined
});
});
it('should handle incomplete import data', () => {
const inputData = {
imports: [
{
path: 'valid-module',
version: 'v1.0.0'
},
{
// missing path
url: 'https://example.com/module.git'
},
{} // empty import
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.imports).toHaveLength(3);
expect(config.imports[0]).toEqual({
path: 'valid-module',
url: undefined,
version: 'v1.0.0',
mounts: []
});
expect(config.imports[1]).toEqual({
path: '',
url: 'https://example.com/module.git',
version: undefined,
mounts: []
});
expect(config.imports[2]).toEqual({
path: '',
url: undefined,
version: undefined,
mounts: []
});
});
it('should handle non-array mounts and imports', () => {
const inputData = {
mounts: 'not-an-array',
imports: null
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.mounts).toEqual([]);
expect(config.imports).toEqual([]);
});
it('should handle complex nested mount configuration in imports', () => {
const inputData = {
imports: [
{
path: 'complex-module',
mounts: [
{
source: 'content',
target: 'content',
lang: 'en'
},
{
source: 'static',
target: 'assets'
}
]
}
]
};
const config = (0, module_1.decodeModuleConfig)(inputData);
expect(config.imports[0].mounts).toHaveLength(2);
expect(config.imports[0].mounts[0]).toEqual({
source: 'content',
target: 'content',
lang: 'en'
});
expect(config.imports[0].mounts[1]).toEqual({
source: 'static',
target: 'assets'
});
});
});
describe('isEmptyModuleConfig', () => {
it('should return true for empty configuration', () => {
const emptyConfig = {
mounts: [],
imports: []
};
expect((0, module_1.isEmptyModuleConfig)(emptyConfig)).toBe(true);
});
it('should return false for configuration with mounts', () => {
const configWithMounts = {
mounts: [
{
source: 'content',
target: 'content'
}
],
imports: []
};
expect((0, module_1.isEmptyModuleConfig)(configWithMounts)).toBe(false);
});
it('should return false for configuration with imports', () => {
const configWithImports = {
mounts: [],
imports: [
{
path: 'some-module',
mounts: []
}
]
};
expect((0, module_1.isEmptyModuleConfig)(configWithImports)).toBe(false);
});
it('should return false for configuration with both mounts and imports', () => {
const fullConfig = {
mounts: [
{
source: 'content',
target: 'content'
}
],
imports: [
{
path: 'some-module',
mounts: []
}
]
};
expect((0, module_1.isEmptyModuleConfig)(fullConfig)).toBe(false);
});
it('should work with EmptyModuleConfig constant', () => {
expect((0, module_1.isEmptyModuleConfig)(module_1.EmptyModuleConfig)).toBe(true);
});
});
});
//# sourceMappingURL=vo-module.test.js.map