|
7 | 7 | import { expect } from 'chai';
|
8 | 8 | import { MetadataRegistry } from '../../src';
|
9 | 9 | import { registry as defaultRegistry } from '../../src/registry/registry';
|
10 |
| -import { MetadataType } from '../../src/registry/types'; |
| 10 | +import { MetadataType, TransformerStrategy, DecompositionStrategy } from '../../src/registry/types'; |
11 | 11 |
|
12 | 12 | describe('Registry Validation', () => {
|
13 | 13 | const registry = defaultRegistry as MetadataRegistry;
|
@@ -194,4 +194,108 @@ describe('Registry Validation', () => {
|
194 | 194 | });
|
195 | 195 | });
|
196 | 196 | });
|
| 197 | + |
| 198 | + describe('top level required properties', () => { |
| 199 | + describe('all have names and directoryName', () => { |
| 200 | + Object.entries(registry.types).forEach(([key, type]) => { |
| 201 | + it(`${type.id} has a name`, () => { |
| 202 | + expect(type.name).to.be.a('string'); |
| 203 | + }); |
| 204 | + it(`${type.id} has a directoryName`, () => { |
| 205 | + expect(type.directoryName).to.be.a('string'); |
| 206 | + }); |
| 207 | + }); |
| 208 | + }); |
| 209 | + }); |
| 210 | + |
| 211 | + describe('valid strategies', () => { |
| 212 | + const typesWithStrategies = Object.values(registry.types).filter((type) => type.strategies); |
| 213 | + |
| 214 | + // there isn't an enum for this in Types, to the known are hardcoded here |
| 215 | + describe('valid, known adapters', () => { |
| 216 | + typesWithStrategies.forEach((type) => { |
| 217 | + it(`${type.id} has a valid adapter`, () => { |
| 218 | + expect(['default', 'mixedContent', 'bundle', 'matchingContentFile', 'decomposed']).includes( |
| 219 | + type.strategies.adapter |
| 220 | + ); |
| 221 | + }); |
| 222 | + }); |
| 223 | + }); |
| 224 | + |
| 225 | + describe('adapter = matchingContentFile => no other strategy properties', () => { |
| 226 | + typesWithStrategies |
| 227 | + .filter((t) => t.strategies.adapter === 'matchingContentFile') |
| 228 | + .forEach((type) => { |
| 229 | + it(`${type.id} has no other strategy properties`, () => { |
| 230 | + expect(type.strategies.decomposition).to.be.undefined; |
| 231 | + expect(type.strategies.recomposition).to.be.undefined; |
| 232 | + expect(type.strategies.transformer).to.be.undefined; |
| 233 | + }); |
| 234 | + }); |
| 235 | + }); |
| 236 | + |
| 237 | + describe('adapter = bundle => no other strategy properties', () => { |
| 238 | + typesWithStrategies |
| 239 | + .filter((t) => t.strategies.adapter === 'bundle') |
| 240 | + .forEach((type) => { |
| 241 | + it(`${type.id} has no other strategy properties`, () => { |
| 242 | + expect(type.strategies.decomposition).to.be.undefined; |
| 243 | + expect(type.strategies.recomposition).to.be.undefined; |
| 244 | + expect(type.strategies.transformer).to.be.undefined; |
| 245 | + }); |
| 246 | + }); |
| 247 | + }); |
| 248 | + |
| 249 | + describe('adapter = decomposed => has transformer and decomposition props', () => { |
| 250 | + typesWithStrategies |
| 251 | + .filter((t) => t.strategies.adapter === 'decomposed') |
| 252 | + .forEach((type) => { |
| 253 | + it(`${type.id} has expected properties`, () => { |
| 254 | + expect(type.strategies.decomposition).to.be.a('string'); |
| 255 | + expect( |
| 256 | + [DecompositionStrategy.FolderPerType.valueOf(), DecompositionStrategy.TopLevel.valueOf()].includes( |
| 257 | + type.strategies.decomposition |
| 258 | + ) |
| 259 | + ).to.be.true; |
| 260 | + expect(type.strategies.transformer).to.be.a('string'); |
| 261 | + expect( |
| 262 | + [ |
| 263 | + TransformerStrategy.Standard.valueOf(), |
| 264 | + TransformerStrategy.Decomposed.valueOf(), |
| 265 | + TransformerStrategy.StaticResource.valueOf(), |
| 266 | + TransformerStrategy.NonDecomposed.valueOf(), |
| 267 | + ].includes(type.strategies.transformer) |
| 268 | + ).to.be.true; |
| 269 | + expect(type.strategies.recomposition).to.be.undefined; |
| 270 | + }); |
| 271 | + }); |
| 272 | + }); |
| 273 | + it('no standard types specified in registry', () => { |
| 274 | + expect(typesWithStrategies.filter((t) => t.strategies.transformer === 'standard')).to.have.length(0); |
| 275 | + }); |
| 276 | + describe('adapter = mixedContent => has no decomposition/recomposition props', () => { |
| 277 | + typesWithStrategies |
| 278 | + .filter((t) => t.strategies.adapter === 'mixedContent') |
| 279 | + .forEach((type) => { |
| 280 | + it(`${type.id} has expected properties`, () => { |
| 281 | + expect(type.strategies.decomposition).to.be.undefined; |
| 282 | + expect(type.strategies.recomposition).to.be.undefined; |
| 283 | + type.strategies.transformer |
| 284 | + ? expect(type.strategies.transformer).to.be.a('string') |
| 285 | + : expect(type.strategies.transformer).to.be.undefined; |
| 286 | + }); |
| 287 | + }); |
| 288 | + }); |
| 289 | + }); |
| 290 | + |
| 291 | + describe('folders', () => { |
| 292 | + const folderTypes = Object.values(registry.types).filter((type) => type.inFolder); |
| 293 | + |
| 294 | + folderTypes.forEach((type) => { |
| 295 | + it(`${type.name} has a valid folderType in the registry`, () => { |
| 296 | + expect(type.folderType).to.not.be.undefined; |
| 297 | + expect(registry.types[type.folderType]).to.be.an('object'); |
| 298 | + }); |
| 299 | + }); |
| 300 | + }); |
197 | 301 | });
|
0 commit comments