import { styles, CLI, Project, Tutorial } from '../src/context'
import { FS } from '../src/models/FS'
import session from '../src/models/Session'

// **
// * Initial mock setup for a singleton CLI instance that is used in every command unit test
// **
export function withCli(fn: (cli: CLI) => void) {
  describe('', () => {
    jest.mock('../src/models/FS')
    jest.mock('../src/context/CLI')
    jest.mock('../src/context/Project')
    jest.mock('../src/context/Tutorial')

    const cli = new CLI(session)

    beforeEach(() => {
      session.captureException = jest.fn().mockReturnValue(null)

      cli.fs = new FS({ session })
      cli.fs.serviceFile = {
        ampt: {
          org: 'test-org',
          app: 'test-app'
        }
      }
      cli.fs.read = jest.fn().mockResolvedValue({
        serviceFile: cli.fs.serviceFile,
        devDependencies: {},
        dependencies: {},
        hasDevScript: false
      })
      cli.fs.writeDataFile = jest.fn().mockResolvedValue(null)
      cli.fs.writeServiceFile = jest.fn().mockResolvedValue(null)

      cli.tutorial = new Tutorial(cli)
      cli.project = new Project(cli)
      cli.styles = styles
    })

    fn(cli)

    afterEach(() => {
      jest.clearAllMocks()
    })
  })
}
