Skip to content

Commit 8e775e6

Browse files
authored
Merge pull request #10 from abraham/copilot/fix-9
Add generate script to parse Mastodon entity files
2 parents 7f06eb4 + b619090 commit 8e775e6

File tree

4 files changed

+329
-5
lines changed

4 files changed

+329
-5
lines changed

package-lock.json

Lines changed: 78 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "tsc",
99
"start": "node dist/index.js",
1010
"dev": "ts-node src/index.ts",
11+
"generate": "ts-node src/generate.ts",
1112
"test": "jest --passWithNoTests",
1213
"test:watch": "jest --watch",
1314
"clean": "rm -rf dist",
@@ -22,10 +23,14 @@
2223
"license": "MIT",
2324
"devDependencies": {
2425
"@types/jest": "^29.5.0",
26+
"@types/js-yaml": "^4.0.9",
2527
"@types/node": "^20.0.0",
2628
"jest": "^29.5.0",
2729
"ts-jest": "^29.1.0",
2830
"ts-node": "^10.9.0",
2931
"typescript": "^5.0.0"
32+
},
33+
"dependencies": {
34+
"gray-matter": "^4.0.3"
3035
}
31-
}
36+
}

src/__tests__/generate.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { EntityParser, EntityClass, EntityAttribute } from '../generate';
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+
});

0 commit comments

Comments
 (0)