import nock from 'nock' ; import createCommit from '../src/lib/create-commit' ; import { generateToolkit } from './helpers' ; import { Toolkit } from 'actions-toolkit' ; describe ( 'create-commit' , ( ) => { let tools ; let treeParams ; let commitParams ; beforeEach ( ( ) => { nock ( 'https://api.github.com' ) . post ( '/repos/JasonEtco/test/git/commits' ) . reply ( 200 , ( _ , body ) => { commitParams = body ; } ) . post ( '/repos/JasonEtco/test/git/trees' ) . reply ( 200 , ( _ , body ) => { treeParams = body ; } ) ; tools = generateToolkit ( ) ; } ) ; it ( 'creates the tree and commit' , async ( ) => { await createCommit ( tools ) ; expect ( nock . isDone ( ) ) . toBe ( true ) ; expect ( treeParams . tree ) . toHaveLength ( 2 ) ; expect ( treeParams . tree . some ( ( obj ) => obj . path === 'index.js' ) ) . toBe ( true ) ; expect ( commitParams . message ) . toBe ( 'Automatic compilation' ) ; expect ( commitParams . parents ) . toEqual ( [ tools . context . sha ] ) ; } ) ; it ( 'creates the tree and commit' , async ( ) => { jest . spyOn ( tools , 'getPackageJSON' ) . mockReturnValueOnce ( { } ) ; await expect ( ( ) => createCommit ( tools ) ) . rejects . toThrow ( 'Property "main" does not exist in your `package.json`.' ) ; } ) ; } ) ;