-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
83 lines (74 loc) · 3.3 KB
/
index.test.js
File metadata and controls
83 lines (74 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
jest.mock('fs', () => ({
existsSync: jest.fn().mockReturnValue(true),
readFileSync: jest.fn().mockReturnValue('mock schema'),
writeFileSync: jest.fn(),
mkdirSync: jest.fn(),
}));
jest.mock('path', () => ({
join: jest.fn().mockReturnValue('mock/path/to/schema.prisma'),
}));
jest.mock('@prisma/internals', () => ({
getDMMF: jest.fn().mockResolvedValue({
datamodel: {
models: [
{
name: 'User',
fields: [
{
name: 'id',
type: 'Int',
isRequired: true,
isUnique: true,
isId: true,
default: null,
updatedAt: false,
relation: null,
},
{
name: 'email',
type: 'String',
isRequired: true,
isUnique: true,
isId: false,
default: null,
updatedAt: false,
relation: null,
},
],
},
],
},
}),
}));
const { parsePrismaSchema, generateHtmlDocumentation, generateMarkdownDocumentation } = require('./index.js');
describe('Prisma Schema Documentation Generator', () => {
it('should generate light theme HTML documentation correctly', async () => {
const models = await parsePrismaSchema('mock/path/to/schema.prisma');
const htmlContent = generateHtmlDocumentation(models, false);
expect(htmlContent).toContain('<html>');
expect(htmlContent).toContain('<title>Prisma Schema Documentation</title>');
expect(htmlContent).toContain('User');
});
it('should generate dark theme HTML documentation correctly', async () => {
const models = await parsePrismaSchema('mock/path/to/schema.prisma');
const htmlContent = generateHtmlDocumentation(models, true);
expect(htmlContent).toContain('<html>');
expect(htmlContent).toContain('<title>Prisma Schema Documentation</title>');
expect(htmlContent).toContain('User');
});
it('should generate Markdown documentation correctly', async () => {
const models = await parsePrismaSchema('mock/path/to/schema.prisma');
const markdownContent = generateMarkdownDocumentation(models);
expect(markdownContent).toContain('# Prisma Schema Documentation');
expect(markdownContent).toContain('## User');
expect(markdownContent).toContain('| **Type** | Int |');
expect(markdownContent).toContain('### id');
expect(markdownContent).toContain('| **Type** | Int |');
expect(markdownContent).toContain('| **Required** | Yes |');
expect(markdownContent).toContain('| **Attributes**| @id, @unique |');
expect(markdownContent).toContain('### email');
expect(markdownContent).toContain('| **Type** | String |');
expect(markdownContent).toContain('| **Required** | Yes |');
expect(markdownContent).toContain('| **Attributes**| @unique |');
});
});