forked from asyncapi/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
46 lines (36 loc) · 1.44 KB
/
index.test.js
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
const fs = require('fs');
const { rssFeed } = require('../scripts/build-rss.ts');
const { buildPostList } = require('../scripts/build-post-list.ts');
const { buildCaseStudiesList } = require('../scripts/casestudies/index.ts');
const { buildAdoptersList } = require('../scripts/adopters/index.ts');
const { buildFinanceInfoList } = require('../scripts/finance/index.ts');
const { start } = require('../scripts/index.ts');
jest.mock('../scripts/build-rss');
jest.mock('../scripts/build-post-list');
jest.mock('../scripts/casestudies');
jest.mock('../scripts/adopters');
jest.mock('../scripts/finance');
describe('start function', () => {
beforeEach(() => {
jest.clearAllMocks();
});
test('should call all functions in the correct order', async () => {
await start();
expect(buildPostList).toHaveBeenCalled();
expect(rssFeed).toHaveBeenCalledWith(
'blog',
'AsyncAPI Initiative Blog RSS Feed',
'AsyncAPI Initiative Blog',
'rss.xml'
);
expect(buildCaseStudiesList).toHaveBeenCalled();
expect(buildAdoptersList).toHaveBeenCalled();
expect(buildFinanceInfoList).toHaveBeenCalled();
});
test('should throw an error if no finance data is found', async () => {
jest.spyOn(fs, 'readdirSync').mockReturnValue([]);
await expect(start()).rejects.toThrow('No finance data found in the finance directory.');
expect(buildFinanceInfoList).not.toHaveBeenCalled();
fs.readdirSync.mockRestore();
});
});