1+ // Test backward compatibility of the main generate file exports
12import { EntityParser , EntityClass , EntityAttribute , MethodParser , ApiMethodsFile , ApiMethod , ApiParameter } from '../generate' ;
2- import * as fs from 'fs' ;
3- import * as path from 'path' ;
43
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 ( ) ;
4+ describe ( 'Generate module backward compatibility' , ( ) => {
5+ test ( 'should export all interfaces and classes' , ( ) => {
6+ // Test that all exports are available from the main module
7+ expect ( EntityParser ) . toBeDefined ( ) ;
8+ expect ( MethodParser ) . toBeDefined ( ) ;
489
49- // Find entities with optional/deprecated attributes
50- let foundOptional = false ;
51- let foundDeprecated = false ;
10+ // Test that interfaces can be used (they should be defined types)
11+ const parser = new EntityParser ( ) ;
12+ expect ( parser ) . toBeInstanceOf ( EntityParser ) ;
5213
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 ) ;
14+ const methodParser = new MethodParser ( ) ;
15+ expect ( methodParser ) . toBeInstanceOf ( MethodParser ) ;
6216 } ) ;
6317
64- test ( 'should parse entity with simple structure' , ( ) => {
18+ test ( 'should maintain existing API surface' , ( ) => {
19+ // Ensure backward compatibility by testing that existing imports still work
20+ const parser = new EntityParser ( ) ;
6521 const entities = parser . parseAllEntities ( ) ;
22+ expect ( entities ) . toBeInstanceOf ( Array ) ;
6623
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- describe ( 'MethodParser' , ( ) => {
85- let methodParser : MethodParser ;
86-
87- beforeEach ( ( ) => {
88- methodParser = new MethodParser ( ) ;
89- } ) ;
90-
91- test ( 'should parse all method files without throwing errors' , ( ) => {
92- expect ( ( ) => {
93- const methodFiles = methodParser . parseAllMethods ( ) ;
94- expect ( methodFiles ) . toBeInstanceOf ( Array ) ;
95- expect ( methodFiles . length ) . toBeGreaterThan ( 0 ) ;
96- } ) . not . toThrow ( ) ;
97- } ) ;
98-
99- test ( 'should parse method files and extract basic structure' , ( ) => {
100- const methodFiles = methodParser . parseAllMethods ( ) ;
101-
102- // Verify we found method files
103- expect ( methodFiles . length ) . toBeGreaterThan ( 30 ) ; // Should be around 40 method files
104-
105- // Find a specific method file to test
106- const appsMethodFile = methodFiles . find ( f => f . name . includes ( 'apps' ) ) ;
107- expect ( appsMethodFile ) . toBeDefined ( ) ;
108-
109- if ( appsMethodFile ) {
110- expect ( appsMethodFile . name ) . toContain ( 'apps' ) ;
111- expect ( appsMethodFile . description ) . toContain ( 'OAuth' ) ;
112- expect ( appsMethodFile . methods . length ) . toBeGreaterThan ( 0 ) ;
113-
114- // Check that create app method exists
115- const createMethod = appsMethodFile . methods . find ( method =>
116- method . name . toLowerCase ( ) . includes ( 'create' ) && method . endpoint . includes ( '/api/v1/apps' )
117- ) ;
118- expect ( createMethod ) . toBeDefined ( ) ;
119-
120- if ( createMethod ) {
121- expect ( createMethod . httpMethod ) . toBe ( 'POST' ) ;
122- expect ( createMethod . endpoint ) . toBe ( '/api/v1/apps' ) ;
123- expect ( createMethod . description ) . toBeTruthy ( ) ;
124- }
125- }
126- } ) ;
127-
128- test ( 'should parse method parameters correctly' , ( ) => {
129- const methodFiles = methodParser . parseAllMethods ( ) ;
130-
131- // Find a method with parameters
132- let foundMethodWithParams = false ;
133- let foundRequiredParam = false ;
134-
135- for ( const methodFile of methodFiles ) {
136- for ( const method of methodFile . methods ) {
137- if ( method . parameters && method . parameters . length > 0 ) {
138- foundMethodWithParams = true ;
139-
140- for ( const param of method . parameters ) {
141- expect ( param . name ) . toBeTruthy ( ) ;
142- expect ( param . description ) . toBeTruthy ( ) ;
143-
144- if ( param . required ) {
145- foundRequiredParam = true ;
146- }
147- }
148- }
149- }
150- }
151-
152- expect ( foundMethodWithParams ) . toBe ( true ) ;
153- expect ( foundRequiredParam ) . toBe ( true ) ;
154- } ) ;
155-
156- test ( 'should extract HTTP methods and endpoints correctly' , ( ) => {
24+ const methodParser = new MethodParser ( ) ;
15725 const methodFiles = methodParser . parseAllMethods ( ) ;
158-
159- // Find some specific methods to verify
160- let foundGetMethod = false ;
161- let foundPostMethod = false ;
162- let foundDeleteMethod = false ;
163-
164- for ( const methodFile of methodFiles ) {
165- for ( const method of methodFile . methods ) {
166- if ( method . httpMethod === 'GET' ) foundGetMethod = true ;
167- if ( method . httpMethod === 'POST' ) foundPostMethod = true ;
168- if ( method . httpMethod === 'DELETE' ) foundDeleteMethod = true ;
169-
170- // Verify endpoint format (all endpoints should start with /)
171- expect ( method . endpoint ) . toMatch ( / ^ \/ / ) ;
172- }
173- }
174-
175- expect ( foundGetMethod ) . toBe ( true ) ;
176- expect ( foundPostMethod ) . toBe ( true ) ;
177- expect ( foundDeleteMethod ) . toBe ( true ) ;
26+ expect ( methodFiles ) . toBeInstanceOf ( Array ) ;
17827 } ) ;
17928} ) ;
0 commit comments