Repository navigation
Expand file tree
/
Copy pathmock-data.test.ts
More file actions
82 lines (71 loc) · 3.1 KB
/
Copy pathmock-data.test.ts
File metadata and controls
82 lines (71 loc) · 3.1 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
import { describe, expect, it } from 'bun:test';
import {
isMockRepo,
fetchMockRepoInfo,
fetchMockFlatTree,
fetchMockFileContents,
fetchMockContributors,
fetchMockTimeline,
fetchMockRepoBranches,
} from './mock-data';
describe('github/mock-data', () => {
it('isMockRepo: checks mock owner', () => {
expect(isMockRepo('mock')).toBe(true);
expect(isMockRepo('MOCK')).toBe(true);
expect(isMockRepo('Mock')).toBe(true);
expect(isMockRepo('real')).toBe(false);
expect(isMockRepo('')).toBe(false);
});
it('fetchMockRepoInfo: returns mock info for gitsdm and others', async () => {
const infoGitsdm = await fetchMockRepoInfo('mock', 'gitsdm', 'main');
expect(infoGitsdm.repo).toBe('gitsdm');
expect(infoGitsdm.owner).toBe('mock');
expect(infoGitsdm.stars).toBe(128);
expect(infoGitsdm.defaultBranch).toBe('main');
expect(infoGitsdm.license).toBe('MIT');
expect(infoGitsdm.sha).toContain('mock');
const infoOther = await fetchMockRepoInfo('mock', 'other');
expect(infoOther.repo).toBe('other');
expect(infoOther.stars).toBe(45);
expect(infoOther.defaultBranch).toBe('main');
// Branch name override
const infoBranch = await fetchMockRepoInfo('mock', 'gitsdm', 'develop');
expect(infoBranch.defaultBranch).toBe('develop');
});
it('fetchMockFlatTree: returns files for gitsdm and others', async () => {
const treeGitsdm = await fetchMockFlatTree('mock', 'gitsdm');
expect(treeGitsdm.items.length).toBeGreaterThan(0);
expect(treeGitsdm.truncated).toBe(false);
expect(treeGitsdm.items[0].type).toBe('blob');
const treeOther = await fetchMockFlatTree('mock', 'other');
expect(treeOther.items.length).toBeGreaterThan(0);
});
it('fetchMockFileContents: returns mock files contents and placeholders', async () => {
const contentGitsdm = await fetchMockFileContents('mock', 'gitsdm', ['package.json', 'nonexistent.ts']);
expect(contentGitsdm['package.json']).toContain('gitsdm');
expect(contentGitsdm['nonexistent.ts']).toContain('mock repository file');
const contentOther = await fetchMockFileContents('mock', 'other', ['package.json', 'nonexistent.ts']);
expect(contentOther['package.json']).toContain('mock-todo-app');
expect(contentOther['nonexistent.ts']).toContain('mock repository file');
});
it('fetchMockContributors: returns contributors list', async () => {
const list = await fetchMockContributors();
expect(list.length).toBeGreaterThan(0);
expect(list[0].login).toBe('mbayue');
expect(list[0].contributions).toBe(84);
});
it('fetchMockTimeline: returns timeline weeks', async () => {
const timeline = await fetchMockTimeline();
expect(timeline.length).toBe(8);
expect(timeline[0].commits.length).toBeGreaterThan(0);
expect(timeline[0].week).toBeTruthy();
});
it('fetchMockRepoBranches: returns branches list', async () => {
const branches = await fetchMockRepoBranches();
expect(branches).toEqual([
{ name: 'main', protected: true },
{ name: 'develop', protected: false },
{ name: 'feature/mock-mode', protected: false },
]);
});
});