|
1 | | -import { EntityParser, EntityClass, EntityAttribute, MethodParser, ApiMethodsFile, ApiMethod, ApiParameter } from '../generate'; |
| 1 | +import { MethodParser } from '../../parsers/MethodParser'; |
2 | 2 | import * as fs from 'fs'; |
3 | 3 | import * as path from 'path'; |
4 | 4 |
|
5 | | -describe('EntityParser', () => { |
6 | | - let parser: EntityParser; |
7 | | - |
8 | | - beforeEach(() => { |
9 | | - parser = new EntityParser(); |
10 | | - }); |
11 | | - |
12 | | - test('should parse all entities without throwing errors', () => { |
13 | | - expect(() => { |
14 | | - const entities = parser.parseAllEntities(); |
15 | | - expect(entities).toBeInstanceOf(Array); |
16 | | - expect(entities.length).toBeGreaterThan(0); |
17 | | - }).not.toThrow(); |
18 | | - }); |
19 | | - |
20 | | - test('should parse entities and extract basic structure', () => { |
21 | | - const entities = parser.parseAllEntities(); |
22 | | - |
23 | | - // Verify we found entities |
24 | | - expect(entities.length).toBeGreaterThan(50); // Should be around 64 entities |
25 | | - |
26 | | - // Find a specific entity to test |
27 | | - const accountEntity = entities.find(e => e.name === 'Account'); |
28 | | - expect(accountEntity).toBeDefined(); |
29 | | - |
30 | | - if (accountEntity) { |
31 | | - expect(accountEntity.name).toBe('Account'); |
32 | | - expect(accountEntity.description).toContain('user of Mastodon'); |
33 | | - expect(accountEntity.attributes.length).toBeGreaterThan(20); // Account has many attributes |
34 | | - |
35 | | - // Check some specific attributes exist |
36 | | - const idAttribute = accountEntity.attributes.find(attr => attr.name === 'id'); |
37 | | - expect(idAttribute).toBeDefined(); |
38 | | - expect(idAttribute?.type).toContain('String'); |
39 | | - |
40 | | - const usernameAttribute = accountEntity.attributes.find(attr => attr.name === 'username'); |
41 | | - expect(usernameAttribute).toBeDefined(); |
42 | | - expect(usernameAttribute?.type).toBe('String'); |
43 | | - } |
44 | | - }); |
45 | | - |
46 | | - test('should correctly identify optional and deprecated attributes', () => { |
47 | | - const entities = parser.parseAllEntities(); |
48 | | - |
49 | | - // Find entities with optional/deprecated attributes |
50 | | - let foundOptional = false; |
51 | | - let foundDeprecated = false; |
52 | | - |
53 | | - for (const entity of entities) { |
54 | | - for (const attr of entity.attributes) { |
55 | | - if (attr.optional) foundOptional = true; |
56 | | - if (attr.deprecated) foundDeprecated = true; |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - expect(foundOptional).toBe(true); |
61 | | - expect(foundDeprecated).toBe(true); |
62 | | - }); |
63 | | - |
64 | | - test('should parse entity with simple structure', () => { |
65 | | - const entities = parser.parseAllEntities(); |
66 | | - |
67 | | - // Find Application entity which has a simpler structure |
68 | | - const applicationEntity = entities.find(e => e.name === 'Application'); |
69 | | - expect(applicationEntity).toBeDefined(); |
70 | | - |
71 | | - if (applicationEntity) { |
72 | | - expect(applicationEntity.name).toBe('Application'); |
73 | | - expect(applicationEntity.description).toContain('interfaces with the REST API'); |
74 | | - expect(applicationEntity.attributes.length).toBeGreaterThan(0); |
75 | | - |
76 | | - // Check that name attribute exists |
77 | | - const nameAttribute = applicationEntity.attributes.find(attr => attr.name === 'name'); |
78 | | - expect(nameAttribute).toBeDefined(); |
79 | | - expect(nameAttribute?.type).toBe('String'); |
80 | | - } |
81 | | - }); |
82 | | -}); |
83 | | - |
84 | 5 | describe('MethodParser', () => { |
85 | 6 | let methodParser: MethodParser; |
86 | 7 |
|
|
0 commit comments