@@ -100,7 +100,7 @@ describe('lb4 controller', () => {
100
100
restCLIInput ,
101
101
) ;
102
102
103
- it ( 'creates REST CRUD template with valid input' , async ( ) => {
103
+ it ( 'creates REST CRUD template with valid input - id omitted ' , async ( ) => {
104
104
await testUtils
105
105
. executeGenerator ( generator )
106
106
. inDir ( SANDBOX_PATH , ( ) =>
@@ -111,7 +111,23 @@ describe('lb4 controller', () => {
111
111
)
112
112
. withPrompts ( restCLIInputComplete ) ;
113
113
114
- checkRestCrudContents ( ) ;
114
+ checkRestCrudContents ( { idOmitted : true } ) ;
115
+ } ) ;
116
+
117
+ it ( 'creates REST CRUD template with valid input' , async ( ) => {
118
+ await testUtils
119
+ . executeGenerator ( generator )
120
+ . inDir ( SANDBOX_PATH , ( ) =>
121
+ testUtils . givenLBProject ( SANDBOX_PATH , {
122
+ includeDummyModel : true ,
123
+ includeDummyRepository : true ,
124
+ } ) ,
125
+ )
126
+ . withPrompts (
127
+ Object . assign ( { } , restCLIInputComplete , { idOmitted : false } ) ,
128
+ ) ;
129
+
130
+ checkRestCrudContents ( { idOmitted : false } ) ;
115
131
} ) ;
116
132
117
133
describe ( 'HTTP REST path' , ( ) => {
@@ -228,13 +244,44 @@ function checkBasicContents() {
228
244
assert . fileContent ( expectedFile , / c o n s t r u c t o r \( \) { } / ) ;
229
245
}
230
246
247
+ function checkCreateContentsWithIdOmitted ( ) {
248
+ const postCreateRegEx = [
249
+ / \@ p o s t \( ' \/ p r o d u c t - r e v i e w s ' , { / ,
250
+ / r e s p o n s e s : { / ,
251
+ / ' 2 0 0 ' : { / ,
252
+ / d e s c r i p t i o n : ' P r o d u c t R e v i e w m o d e l i n s t a n c e ' / ,
253
+ / c o n t e n t : { ' a p p l i c a t i o n \/ j s o n ' : { schema: g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w \) } } , \s { 1 , } } , \s { 1 , } } , \s { 1 , } } \) / ,
254
+ / a s y n c c r e a t e \( \s + \@ r e q u e s t B o d y \( { \s + c o n t e n t : { \s + ' a p p l i c a t i o n \/ j s o n ' : { \s + s c h e m a : g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w , { \s + t i t l e : ' N e w P r o d u c t R e v i e w ' , \s + e x c l u d e : \[ ' p r o d u c t I d ' \] , \s + } \) , \s + } , \s + } , \s + } \) \s + p r o d u c t R e v i e w : O m i t < P r o d u c t R e v i e w , ' p r o d u c t I d ' > , \s + \) / ,
255
+ ] ;
256
+ postCreateRegEx . forEach ( regex => {
257
+ assert . fileContent ( expectedFile , regex ) ;
258
+ } ) ;
259
+ }
260
+
261
+ /**
262
+ * Check the contents for operation 'create' when id is not required.
263
+ */
264
+ function checkCreateContents ( ) {
265
+ const postCreateRegEx = [
266
+ / \@ p o s t \( ' \/ p r o d u c t - r e v i e w s ' , { / ,
267
+ / r e s p o n s e s : { / ,
268
+ / ' 2 0 0 ' : { / ,
269
+ / d e s c r i p t i o n : ' P r o d u c t R e v i e w m o d e l i n s t a n c e ' / ,
270
+ / c o n t e n t : { ' a p p l i c a t i o n \/ j s o n ' : { schema: g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w \) } } , \s { 1 , } } , \s { 1 , } } , \s { 1 , } } \) / ,
271
+ / a s y n c c r e a t e \( \s + \@ r e q u e s t B o d y \( { \s + c o n t e n t : { \s + ' a p p l i c a t i o n \/ j s o n ' : { \s + s c h e m a : g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w , { \s + t i t l e : ' N e w P r o d u c t R e v i e w ' , \s + } \) , \s + } , \s + } , \s + } \) \s + p r o d u c t R e v i e w : P r o d u c t R e v i e w , \s + \) / ,
272
+ ] ;
273
+ postCreateRegEx . forEach ( regex => {
274
+ assert . fileContent ( expectedFile , regex ) ;
275
+ } ) ;
276
+ }
277
+
231
278
/**
232
279
* Assertions against the template to determine if it contains the
233
280
* required signatures for a REST CRUD controller, specifically to ensure
234
281
* that decorators are grouped correctly (for their corresponding
235
282
* target functions)
236
283
*/
237
- function checkRestCrudContents ( ) {
284
+ function checkRestCrudContents ( options ) {
238
285
assert . fileContent ( expectedFile , / c l a s s P r o d u c t R e v i e w C o n t r o l l e r / ) ;
239
286
240
287
// Repository and injection
@@ -243,17 +290,11 @@ function checkRestCrudContents() {
243
290
244
291
// Assert that the decorators are present in the correct groupings!
245
292
// @post - create
246
- const postCreateRegEx = [
247
- / \@ p o s t \( ' \/ p r o d u c t - r e v i e w s ' , { / ,
248
- / r e s p o n s e s : { / ,
249
- / ' 2 0 0 ' : { / ,
250
- / d e s c r i p t i o n : ' P r o d u c t R e v i e w m o d e l i n s t a n c e ' / ,
251
- / c o n t e n t : { ' a p p l i c a t i o n \/ j s o n ' : { schema: g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w \) } } , \s { 1 , } } , \s { 1 , } } , \s { 1 , } } \) / ,
252
- / a s y n c c r e a t e \( \s + \@ r e q u e s t B o d y \( { \s + c o n t e n t : { \s + ' a p p l i c a t i o n \/ j s o n ' : { \s + s c h e m a : g e t M o d e l S c h e m a R e f \( P r o d u c t R e v i e w , { \s + t i t l e : ' N e w P r o d u c t R e v i e w ' , \s + e x c l u d e : \[ ' p r o d u c t I d ' \] , \s + } \) , \s + } , \s + } , \s + } \) \s + p r o d u c t R e v i e w : O m i t < P r o d u c t R e v i e w , ' p r o d u c t I d ' > , \s + \) / ,
253
- ] ;
254
- postCreateRegEx . forEach ( regex => {
255
- assert . fileContent ( expectedFile , regex ) ;
256
- } ) ;
293
+ if ( options && options . idOmitted ) {
294
+ checkCreateContentsWithIdOmitted ( ) ;
295
+ } else {
296
+ checkCreateContents ( ) ;
297
+ }
257
298
258
299
// @get - count
259
300
const getCountRegEx = [
0 commit comments