11import { describe, it, expect } from 'vitest';
22import { createEntityTypes } from '../types/entity-yaml.js';
3- import { normalizeTypes } from '../types/index.js';
3+ import { normalizeTypes, ResolveTypeFn } from '../types/index.js';
44import { entityFileSchema, entityFileDefaultSchema } from '@redocly/config';
5-
65describe('entity-yaml', () => {
76 it('should create entity types with discriminator', () => {
87 const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
@@ -18,36 +17,39 @@ describe('entity-yaml', () => {
1817 expect(entityTypes).toHaveProperty('EntityFileArray');
1918 });
2019
21- it('should resolve entity type based on discriminator for array items', () => {
20+ it('should resolve entity type to default for array items', () => {
2221 const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
2322 const normalizedTypes = normalizeTypes(entityTypes);
2423
2524 const entityFileArrayNode = normalizedTypes['EntityFileArray'];
26- if (typeof entityFileArrayNode.items === 'function') {
27- const userEntity = {
28- type: 'user',
29- key: 'john-doe',
30- title: 'John Doe',
31- metadata: { email: 'john@example.com' },
32- };
33- const resolvedType = entityFileArrayNode.items(userEntity, 'root');
3425
35- expect(resolvedType).toBeTruthy();
36- if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
37- expect(resolvedType.name).toBe('user');
38- if ('properties' in resolvedType) {
39- expect(resolvedType.properties).toHaveProperty('metadata');
40- }
41- }
26+ const unknownEntity = { key: 'unknown', title: 'Unknown' };
27+ const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(unknownEntity, 'root');
28+
29+ expect(resolvedType).toBeTruthy();
30+ if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
31+ expect(resolvedType.name).toBe('EntityFileDefault');
4232 }
33+ });
4334
44- if (typeof entityFileArrayNode.items === 'function') {
45- const unknownEntity = { key: 'unknown', title: 'Unknown' };
46- const resolvedType = entityFileArrayNode.items(unknownEntity, 'root');
35+ it('should resolve entity type based on discriminator for array items', () => {
36+ const entityTypes = createEntityTypes(entityFileSchema, entityFileDefaultSchema);
37+ const normalizedTypes = normalizeTypes(entityTypes);
38+
39+ const entityFileArrayNode = normalizedTypes['EntityFileArray'];
40+ const userEntity = {
41+ type: 'user',
42+ key: 'john-doe',
43+ title: 'John Doe',
44+ metadata: { email: 'john@example.com' },
45+ };
46+ const resolvedType = (entityFileArrayNode.items as ResolveTypeFn)(userEntity, 'root');
4747
48- expect(resolvedType).toBeTruthy();
49- if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
50- expect(resolvedType.name).toBe('EntityFileDefault');
48+ expect(resolvedType).toBeTruthy();
49+ if (resolvedType && typeof resolvedType === 'object' && 'name' in resolvedType) {
50+ expect(resolvedType.name).toBe('user');
51+ if ('properties' in resolvedType) {
52+ expect(resolvedType.properties).toHaveProperty('metadata');
5153 }
5254 }
5355 });
0 commit comments