Skip to content

Commit a2b549c

Browse files
Add PuterModule test
1 parent 3d1ddf7 commit a2b549c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/PuterModule.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
3+
vi.spyOn(console, 'log').mockImplementation(() => { });
4+
5+
const mockSetAuthToken = vi.hoisted(() => vi.fn());
6+
7+
vi.mock('conf', () => {
8+
const Conf = vi.fn(() => ({
9+
get: vi.fn((key) => {
10+
if (key === 'selected_profile') return 'test-uuid';
11+
if (key === 'profiles') return [{
12+
uuid: 'test-uuid',
13+
token: 'test-token'
14+
}];
15+
return null;
16+
}),
17+
set: vi.fn(),
18+
clear: vi.fn(),
19+
}));
20+
return { default: Conf };
21+
});
22+
23+
vi.mock('@heyputer/puter.js', () => ({
24+
puter: {
25+
setAuthToken: mockSetAuthToken,
26+
}
27+
}));
28+
29+
let initPuterModule;
30+
let getPuter;
31+
32+
beforeEach(async () => {
33+
vi.resetModules();
34+
const module = await import('../src/modules/PuterModule.js');
35+
initPuterModule = module.initPuterModule;
36+
getPuter = module.getPuter;
37+
});
38+
39+
describe('initPuterModule', () => {
40+
it('should call setAuthToken when initialized', () => {
41+
initPuterModule();
42+
expect(mockSetAuthToken).toHaveBeenCalledWith(expect.stringContaining('test-token'));
43+
});
44+
});
45+
46+
describe('getPuter', () => {
47+
it('should return puter module if initialized', () => {
48+
initPuterModule();
49+
const result = getPuter();
50+
expect(result).toBeDefined();
51+
});
52+
53+
it('should throw error if not initialized', () => {
54+
expect(() => getPuter()).toThrow('Call initPuterModule() first');
55+
});
56+
});

0 commit comments

Comments
 (0)