Skip to content

Commit ef6d76c

Browse files
authored
Merge pull request #15 from abraham/copilot/fix-14
Split code into multiple files with one class or interface per file
2 parents 06c0c25 + ee233a1 commit ef6d76c

File tree

11 files changed

+498
-455
lines changed

11 files changed

+498
-455
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { EntityParser } from '../../parsers/EntityParser';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
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+
});

src/__tests__/generate.test.ts renamed to src/__tests__/parsers/MethodParser.test.ts

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,7 @@
1-
import { EntityParser, EntityClass, EntityAttribute, MethodParser, ApiMethodsFile, ApiMethod, ApiParameter } from '../generate';
1+
import { MethodParser } from '../../parsers/MethodParser';
22
import * as fs from 'fs';
33
import * as path from 'path';
44

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-
845
describe('MethodParser', () => {
856
let methodParser: MethodParser;
867

0 commit comments

Comments
 (0)