import * as assert from "assert" ; import { splitMsg , _splitPrefixes , _splitPrefixesAndDesc , } from "../../generate/parseExisting" ; describe ( "Split an existing message into components" , function ( ) { describe ( "#_splitPrefixesAndDesc" , function ( ) { it ( "handles a description alone" , function ( ) { const value = "foo the bar" ; const expected = { prefixes : "" , description : "foo the bar" , } ; assert . deepStrictEqual ( _splitPrefixesAndDesc ( value ) , expected ) ; } ) ; describe ( "splits correctly with prefix and description set" , function ( ) { it ( "handles a type prefix" , function ( ) { const value = "feat: foo the bar" ; const expected = { prefixes : "feat" , description : "foo the bar" , } ; assert . deepStrictEqual ( _splitPrefixesAndDesc ( value ) , expected ) ; } ) ; it ( "handles a custom prefix" , function ( ) { const value = "[ABC-123]: foo the bar" ; const expected = { prefixes : "[ABC-123]" , description : "foo the bar" , } ; assert . deepStrictEqual ( _splitPrefixesAndDesc ( value ) , expected ) ; } ) ; it ( "handles a custom prefix and type prefix" , function ( ) { const value = "[ABC-123] feat: foo the bar" ; const expected = { prefixes : "[ABC-123] feat" , description : "foo the bar" , } ; assert . deepStrictEqual ( _splitPrefixesAndDesc ( value ) , expected ) ; } ) ; } ) ; } ) ; describe ( "#_splitPrefixes" , function ( ) { it ( "returns empty values for an empty string" , function ( ) { assert . deepStrictEqual ( _splitPrefixes ( "" ) , { customPrefix : "" , typePrefix : "" , } ) ; } ) ; it ( "returns a single word as the type prefix" , function ( ) { assert . deepStrictEqual ( _splitPrefixes ( "foo" ) , { customPrefix : "" , typePrefix : "foo" , } ) ; } ) ; it ( "splits two words correctly as custom and type" , function ( ) { assert . deepStrictEqual ( _splitPrefixes ( "foo bar" ) , { customPrefix : "foo" , typePrefix : "bar" , } ) ; } ) ; it ( "splits three words correctly as two for custom and one for type" , function ( ) { assert . deepStrictEqual ( _splitPrefixes ( "foo bar bazz" ) , { customPrefix : "foo bar" , typePrefix : "bazz" , } ) ; } ) ; it ( "splits four words correctly as three for custom and one for type" , function ( ) { assert . deepStrictEqual ( _splitPrefixes ( "foo bar bazz buzz" ) , { customPrefix : "foo bar bazz" , typePrefix : "buzz" , } ) ; } ) ; } ) ; describe ( "#splitMsg" , function ( ) { it ( "handles a description alone" , function ( ) { assert . deepStrictEqual ( splitMsg ( "abc def" ) , { customPrefix : "" , typePrefix : "" , description : "abc def" , } ) ; assert . deepStrictEqual ( splitMsg ( "[ABCD-1234]" ) , { customPrefix : "" , typePrefix : "" , description : "[ABCD-1234]" , } ) ; assert . deepStrictEqual ( splitMsg ( "[ABCD-1234] abc def" ) , { customPrefix : "" , typePrefix : "" , description : "[ABCD-1234] abc def" , } ) ; } ) ; it ( "handles a type prefix alone" , function ( ) { assert . deepStrictEqual ( splitMsg ( "docs:" ) , { customPrefix : "" , typePrefix : "docs" , description : "" , } ) ; assert . deepStrictEqual ( splitMsg ( "feat:" ) , { customPrefix : "" , typePrefix : "feat" , description : "" , } ) ; assert . deepStrictEqual ( splitMsg ( "docs: " ) , { customPrefix : "" , typePrefix : "docs" , description : "" , } ) ; } ) ; it ( "separates a prefix and description" , function ( ) { assert . deepStrictEqual ( splitMsg ( "docs: abc" ) , { customPrefix : "" , typePrefix : "docs" , description : "abc" , } ) ; assert . deepStrictEqual ( splitMsg ( "docs: abc def" ) , { customPrefix : "" , typePrefix : "docs" , description : "abc def" , } ) ; assert . deepStrictEqual ( splitMsg ( "feat: abc def" ) , { customPrefix : "" , typePrefix : "feat" , description : "abc def" , } ) ; } ) ; describe ( "separates a custom prefix, conventional type, and description" , function ( ) { it ( "handles a Jira number with hard brackets" , function ( ) { assert . deepStrictEqual ( splitMsg ( "[ABCD-1234] docs: abc def" ) , { customPrefix : "[ABCD-1234]" , typePrefix : "docs" , description : "abc def" , } ) ; } ) ; it ( "handles a Jira number with no hard brackets" , function ( ) { assert . deepStrictEqual ( splitMsg ( "ABCD-1234 docs: abc def" ) , { customPrefix : "ABCD-1234" , typePrefix : "docs" , description : "abc def" , } ) ; } ) ; } ) ; } ) ; } ) ;