|
1 | | -import { describe, jest, test, afterEach } from '@jest/globals'; |
| 1 | +import { describe, jest, test, afterEach, beforeEach } from '@jest/globals'; |
2 | 2 | import { mockCommander, mockConfig } from '../mocks.js'; |
3 | 3 |
|
4 | 4 | // setup mocks |
5 | 5 | mockCommander(); |
6 | | -mockConfig(); |
| 6 | +const { getConfigValue } = mockConfig(); |
7 | 7 | const actionChainMock = jest.fn(); |
8 | 8 | jest.unstable_mockModule('src/actions/actionChainWithProgress.js', () => ({ |
9 | 9 | createChainWithProgress: () => actionChainMock, |
@@ -36,35 +36,44 @@ jest.unstable_mockModule('src/cli/auth.js', () => ({ |
36 | 36 |
|
37 | 37 | // import after mocks set up. |
38 | 38 | const { cwdIsEmpty } = await import('../../src/initialize/index.js'); |
39 | | -const { initializeAction } = await import('../../src/cli/initialize.js'); |
40 | 39 |
|
41 | 40 | describe('initialize command', () => { |
| 41 | + beforeEach(() => { |
| 42 | + getConfigValue.mockImplementation((key) => |
| 43 | + key === 'aoc.validation.years' ? [2001, 2002, 2003, 2004] : undefined |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
42 | 47 | afterEach(() => { |
43 | 48 | jest.resetAllMocks(); |
44 | 49 | }); |
45 | 50 |
|
46 | 51 | test('does not ask for confirmation if cwd is empty', async () => { |
| 52 | + const { initializeAction } = await import('../../src/cli/initialize.js'); |
47 | 53 | cwdIsEmpty.mockResolvedValue(true); |
48 | 54 | getAnswersFromUserMock.mockResolvedValue({ answers: {} }); |
49 | 55 | await initializeAction(); |
50 | 56 | expect(assertUserConfirmationMock).not.toHaveBeenCalled(); |
51 | 57 | }); |
52 | 58 |
|
53 | 59 | test('asks for confirmation if cwd is not empty', async () => { |
| 60 | + const { initializeAction } = await import('../../src/cli/initialize.js'); |
54 | 61 | cwdIsEmpty.mockResolvedValue(false); |
55 | 62 | assertUserConfirmationMock.mockResolvedValue(false); |
56 | 63 | await initializeAction(); |
57 | 64 | expect(assertUserConfirmationMock).toHaveBeenCalled(); |
58 | 65 | }); |
59 | 66 |
|
60 | 67 | test('aborts if user does not confirm', async () => { |
| 68 | + const { initializeAction } = await import('../../src/cli/initialize.js'); |
61 | 69 | cwdIsEmpty.mockResolvedValue(false); |
62 | 70 | assertUserConfirmationMock.mockResolvedValue(false); |
63 | 71 | await initializeAction(); |
64 | 72 | expect(actionChainMock).not.toHaveBeenCalled(); |
65 | 73 | }); |
66 | 74 |
|
67 | 75 | test('continues if user confirms', async () => { |
| 76 | + const { initializeAction } = await import('../../src/cli/initialize.js'); |
68 | 77 | cwdIsEmpty.mockResolvedValue(false); |
69 | 78 | assertUserConfirmationMock.mockResolvedValue(true); |
70 | 79 | getAnswersFromUserMock.mockResolvedValue({ answers: {} }); |
|
0 commit comments