import { assert } from "chai" ; import { UserError } from "../logging/user-error" ; import * as config from "." ; suite ( ".parseYML" , function ( ) { suite ( "cannot-prettify-message" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { "cannotPrettifyMessage: Hello" : "Hello" , "cannot-prettify-message: Hello" : "Hello" , "cannot_prettify_message: Hello" : "Hello" , "cannotPrettifyMessage: ''" : "" , "cannotPrettifyMessage: false" : "" , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . equal ( config . parseYML ( validInput ) . cannotPrettifyMessage , expected ) ; } ) ; } for ( const invalidInput of [ "cannotPrettifyMessage:" , "cannot-prettify-message:" , "cannot_prettify_message:" , "cannotPrettifyMessage: 3" , "cannot-prettify-message: 3" , "cannot_prettify_message: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } for ( const emptyInput of [ "pullsOnly: true" , "" , ] ) { test ( `"${ emptyInput }" --> default value` , function ( ) { const have = config . parseYML ( emptyInput ) ; assert . equal ( have . cannotPrettifyMessage , config . defaultValues ( ) . cannotPrettifyMessage ) ; } ) ; } } ) ; suite ( "commit-message" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { "commitMessage: Hello" : "Hello" , "commit-message: Hello" : "Hello" , "commit_message: Hello" : "Hello" , "pullsOnly: true" : "Format {{commitSha}}" , "" : "Format {{commitSha}}" , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . equal ( config . parseYML ( validInput ) . commitMessage , expected ) ; } ) ; } for ( const invalidInput of [ "commitMessage:" , "commit-message:" , "commit_message:" , "commitMessage: 3" , "commit-message: 3" , "commit_message: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } } ) ; suite ( "exclude-branches" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { "excludeBranches: dev" : [ "dev" ] , "exclude-branches: dev" : [ "dev" ] , "exclude_branches: dev" : [ "dev" ] , 'excludeBranches: ["dev", "prod"]' : [ "dev" , "prod" ] , 'exclude-branches: ["dev", "prod"]' : [ "dev" , "prod" ] , 'exclude_branches: ["dev", "prod"]' : [ "dev" , "prod" ] , "pullsOnly: true" : [ ] , "" : [ ] , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . deepEqual ( config . parseYML ( validInput ) . excludeBranches , expected ) ; } ) ; } for ( const invalidInput of [ "excludeBranches:" , "exclude-branches:" , "exclude_branches:" , "excludeBranches: 3" , "exclude-branches: 3" , "exclude_branches: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } } ) ; suite ( "excludeFiles" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { 'excludeFiles: ["foo"]' : [ "foo" ] , 'exclude-files: ["foo"]' : [ "foo" ] , 'exclude_files: ["foo"]' : [ "foo" ] , 'excludeFiles: "foo"' : [ "foo" ] , 'exclude-files: "foo"' : [ "foo" ] , 'exclude_files: "foo"' : [ "foo" ] , "pullsOnly: true" : [ "package-lock.json" ] , "" : [ "package-lock.json" ] , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . deepEqual ( config . parseYML ( validInput ) . excludeFiles , expected ) ; } ) ; } for ( const invalidInput of [ "excludeFiles:" , "exclude-files:" , "exclude_files:" , "excludeFiles: 3" , "exclude-files: 3" , "exclude_files: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } } ) ; suite ( "prettified-message" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { "prettifiedMessage: Hello" : "Hello" , "prettified-message: Hello" : "Hello" , "prettified_message: Hello" : "Hello" , "prettificationNotification: Hello" : "Hello" , "prettification-notification: Hello" : "Hello" , "prettification_notification: Hello" : "Hello" , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . equal ( config . parseYML ( validInput ) . prettifiedMessage , expected ) ; } ) ; } for ( const invalidInput of [ "prettifiedMessage:" , "prettified-message:" , "prettified_message:" , "prettifiedMessage: 3" , "prettified-message: 3" , "prettified_message: 3" , "prettificationNotification:" , "prettification-notification:" , "prettification_notification:" , "prettificationNotification: 3" , "prettification-notification: 3" , "prettification_notification: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } } ) ; suite ( "pullsOnly" , function ( ) { for ( const [ validInput , expected ] of Object . entries ( { "pullsOnly: true" : true , "pulls-only: true" : true , "pulls_only: true" : true , } ) ) { test ( `"${ validInput }" --> ${ expected }` , function ( ) { assert . equal ( config . parseYML ( validInput ) . pullsOnly , expected ) ; } ) ; } for ( const invalidInput of [ "pullsOnly:" , "pulls-only:" , "pulls_only:" , "pullsOnly: 3" , "pulls-only: 3" , "pulls_only: 3" , ] ) { test ( `"${ invalidInput }" throws` , function ( ) { assert . throws ( config . parseYML . bind ( null , invalidInput ) , UserError ) ; } ) ; } } ) ; test ( "unknown key" , function ( ) { assert . throws ( config . parseYML . bind ( null , "zonk: 3" ) , UserError ) ; } ) ; test ( "invalid file structure" , function ( ) { assert . throws ( config . parseYML . bind ( null , "'wrong" ) , UserError ) ; } ) ; } ) ;