|
| 1 | +import { describe, jest, test, afterEach } from '@jest/globals'; |
| 2 | +import { mockLogger, easyMock, easyResolve, mockConfig } from '../mocks.js'; |
| 3 | + |
| 4 | +// setup mocks |
| 5 | +const easyMocks = [['src/commands/stats.js', ['statsAction']]]; |
| 6 | +easyMock(easyMocks); |
| 7 | +mockLogger(); |
| 8 | +const { getConfigValue } = mockConfig(); |
| 9 | + |
| 10 | +// import after mocks set up. |
| 11 | +const { statsAction } = await easyResolve(easyMocks); |
| 12 | +const { autoUpdateReadme } = await import( |
| 13 | + '../../src/tables/autoUpdateReadme.js' |
| 14 | +); |
| 15 | + |
| 16 | +describe('autoUpdateReadme()', () => { |
| 17 | + afterEach(() => { |
| 18 | + jest.resetAllMocks(); |
| 19 | + }); |
| 20 | + |
| 21 | + test('does not update readme if not configured to do so', async () => { |
| 22 | + getConfigValue.mockImplementation((key) => { |
| 23 | + if (key === 'disableReadmeAutoSaveProgress') { |
| 24 | + return true; |
| 25 | + } |
| 26 | + throw new Error('unknown key'); |
| 27 | + }); |
| 28 | + await autoUpdateReadme(); |
| 29 | + expect(statsAction).not.toHaveBeenCalled(); |
| 30 | + }); |
| 31 | + |
| 32 | + test('update readme if configured to do so', async () => { |
| 33 | + getConfigValue.mockImplementation((key) => { |
| 34 | + if (key === 'disableReadmeAutoSaveProgress') { |
| 35 | + return false; |
| 36 | + } |
| 37 | + throw new Error('unknown key'); |
| 38 | + }); |
| 39 | + await autoUpdateReadme(); |
| 40 | + expect(statsAction).toHaveBeenCalled(); |
| 41 | + }); |
| 42 | + |
| 43 | + test('passes save option to statsAction', async () => { |
| 44 | + getConfigValue.mockImplementation((key) => { |
| 45 | + if (key === 'disableReadmeAutoSaveProgress') { |
| 46 | + return false; |
| 47 | + } |
| 48 | + throw new Error('unknown key'); |
| 49 | + }); |
| 50 | + await autoUpdateReadme(); |
| 51 | + expect(statsAction).toHaveBeenCalledWith({ save: true }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments