@@ -5,6 +5,7 @@ import { getPackageChoices } from './get-package-choices';
5
5
import { checkbox , confirm , password , select } from '@inquirer/prompts' ;
6
6
import { configureProject } from './configure-project' ;
7
7
import { Choice , ReleaseTrain } from './models' ;
8
+ import { sortByName } from '@herodevs/utility' ;
8
9
9
10
jest . mock ( './verify-project-type' ) ;
10
11
jest . mock ( '@inquirer/prompts' ) ;
@@ -32,7 +33,7 @@ describe('nesInitCommand', () => {
32
33
let getProductChoicesMock : jest . Mock ;
33
34
let getPackageChoicesMock : jest . Mock ;
34
35
let mockReleaseTrains : ReleaseTrain [ ] = [ ] ;
35
- let mockReleaseTrainChoices : Choice < ReleaseTrain > [ ] = [ ] ;
36
+ let mockReleaseTrainChoices : Choice < ReleaseTrain [ ] > [ ] = [ ] ;
36
37
let configureProjectMock : jest . Mock ;
37
38
38
39
beforeEach ( ( ) => {
@@ -74,8 +75,52 @@ describe('nesInitCommand', () => {
74
75
} ,
75
76
] ,
76
77
} ,
78
+ {
79
+ id : 3 ,
80
+ key : 'release-train-3' ,
81
+ name : 'release train 3' ,
82
+ products : [
83
+ {
84
+ id : 333 ,
85
+ key : 'vue_essentials' ,
86
+ name : 'Vue 3 Essentials' ,
87
+ } ,
88
+ ] ,
89
+ entries : [
90
+ {
91
+ packageVersion : {
92
+ id : 444 ,
93
+ name : '4.5.6' ,
94
+ fqns :
'@neverendingsupport/[email protected] ' ,
95
+ origination : {
96
+ name : 'vue' ,
97
+ type : 'npm' ,
98
+ version : '4.5.6' ,
99
+ } ,
100
+ } ,
101
+ } ,
102
+ ] ,
103
+ } ,
77
104
] ;
78
- mockReleaseTrainChoices = mockReleaseTrains . map ( ( rt ) => ( { name : rt . name , value : rt } ) ) ;
105
+ const products = mockReleaseTrains . reduce ( ( acc , rt ) => {
106
+ rt . products . forEach ( ( product ) => {
107
+ if ( acc [ product . name ] ) {
108
+ acc [ product . name ] . push ( rt ) ;
109
+ } else {
110
+ acc [ product . name ] = [ rt ] ;
111
+ }
112
+ } ) ;
113
+
114
+ return acc ;
115
+ } , { } as { [ key : string ] : ReleaseTrain [ ] } ) ;
116
+
117
+ mockReleaseTrainChoices = Object . entries ( products )
118
+ . map ( ( [ key , value ] ) => ( {
119
+ name : key ,
120
+ value,
121
+ } ) )
122
+ . sort ( sortByName ) ;
123
+
79
124
const packageChoices = mockReleaseTrains [ 0 ] . entries . map ( ( e ) => ( {
80
125
name : e . packageVersion ,
81
126
value : e ,
@@ -87,7 +132,7 @@ describe('nesInitCommand', () => {
87
132
} ) ;
88
133
confirmMock . mockReturnValue ( Promise . resolve ( true ) ) ;
89
134
passwordMock . mockReturnValue ( Promise . resolve ( 'abc123' ) ) ;
90
- selectMock . mockReturnValue ( Promise . resolve ( mockReleaseTrains [ 0 ] ) ) ;
135
+ selectMock . mockReturnValue ( Promise . resolve ( mockReleaseTrainChoices [ 0 ] . value ) ) ;
91
136
checkboxMock . mockReturnValue ( Promise . resolve ( packageChoices . map ( ( c ) => c . value ) ) ) ;
92
137
getProductChoicesMock . mockReturnValue ( Promise . resolve ( mockReleaseTrainChoices ) ) ;
93
138
getPackageChoicesMock . mockReturnValue ( packageChoices ) ;
@@ -150,6 +195,7 @@ describe('nesInitCommand', () => {
150
195
message : 'select a product' ,
151
196
choices : mockReleaseTrainChoices ,
152
197
pageSize : mockReleaseTrainChoices . length ,
198
+ loop : false ,
153
199
} ) ;
154
200
} ) ;
155
201
0 commit comments