@@ -35,8 +35,8 @@ const MOCK_CONTEXT = {
35
35
} ,
36
36
} ;
37
37
const OUTPUT_PATHS = {
38
- javascript : 'src' ,
39
- android : 'app/src/main/java' ,
38
+ javascript : 'src/models ' ,
39
+ android : 'app/src/main/java/com/amplifyframework/datastore/generated/model ' ,
40
40
ios : 'amplify/generated/models' ,
41
41
flutter : 'lib/models' ,
42
42
} ;
@@ -60,7 +60,7 @@ describe('command-models-generates models in expected output path', () => {
60
60
const outputDirectory = path . join ( MOCK_PROJECT_ROOT , OUTPUT_PATHS [ frontend ] ) ;
61
61
const mockedFiles = { } ;
62
62
mockedFiles [ schemaFilePath ] = {
63
- 'schema.graphql' : ' type SimpleModel { id: ID! status: String } ' ,
63
+ 'schema.graphql' : ' type SimpleModel @model { id: ID! status: String } ' ,
64
64
} ;
65
65
mockedFiles [ outputDirectory ] = { } ;
66
66
mockFs ( mockedFiles ) ;
@@ -75,7 +75,7 @@ describe('command-models-generates models in expected output path', () => {
75
75
expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
76
76
77
77
// assert model files are generated in expected output directory
78
- expect ( fs . readdirSync ( outputDirectory ) . length ) . toBeGreaterThan ( 0 ) ;
78
+ expect ( fs . readdirSync ( outputDirectory ) ) . toMatchSnapshot ( ) ;
79
79
} ) ;
80
80
81
81
it ( frontend + ': Should generate models from any subdirectory in schema folder' , async ( ) => {
@@ -99,7 +99,35 @@ describe('command-models-generates models in expected output path', () => {
99
99
expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
100
100
101
101
// assert model files are generated in expected output directory
102
- expect ( fs . readdirSync ( outputDirectory ) . length ) . toBeGreaterThan ( 0 ) ;
102
+ expect ( fs . readdirSync ( outputDirectory ) ) . toMatchSnapshot ( ) ;
103
+ } ) ;
104
+
105
+ it ( frontend + ': Should generate models in overrideOutputDir' , async ( ) => {
106
+ // mock the input and output file structure
107
+ const schemaFilePath = path . join ( MOCK_BACKEND_DIRECTORY , 'api' , MOCK_PROJECT_NAME ) ;
108
+ const outputDirectory = path . join ( MOCK_PROJECT_ROOT , OUTPUT_PATHS [ frontend ] ) ;
109
+ const mockedFiles = { } ;
110
+ mockedFiles [ schemaFilePath ] = {
111
+ 'schema.graphql' : ' type SimpleModel @model { id: ID! status: String } ' ,
112
+ } ;
113
+ const overrideOutputDir = 'some/other/dir' ;
114
+ mockedFiles [ outputDirectory ] = { } ;
115
+ mockedFiles [ overrideOutputDir ] = { } ;
116
+ mockFs ( mockedFiles ) ;
117
+ MOCK_CONTEXT . amplify . getProjectConfig . mockReturnValue ( { frontend : frontend } ) ;
118
+
119
+ // assert empty folder before generation
120
+ expect ( fs . readdirSync ( outputDirectory ) . length ) . toEqual ( 0 ) ;
121
+ expect ( fs . readdirSync ( overrideOutputDir ) . length ) . toEqual ( 0 ) ;
122
+
123
+ await generateModels ( MOCK_CONTEXT , { overrideOutputDir } ) ;
124
+
125
+ // assert model generation succeeds with a single schema file
126
+ expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
127
+
128
+ // assert model files are generated in expected output directory
129
+ expect ( fs . readdirSync ( outputDirectory ) . length ) . toEqual ( 0 ) ;
130
+ expect ( fs . readdirSync ( overrideOutputDir ) . length ) . not . toEqual ( 0 ) ;
103
131
} ) ;
104
132
105
133
if ( frontend === 'flutter' ) {
0 commit comments