@@ -74,6 +74,40 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
7474 },
7575 expectedErrorType : nil ,
7676 },
77+ "package.json file exists" : {
78+ appDirName : "vibrant-butterfly-1234" ,
79+ existingFiles : map [string ]string {
80+ "package.json" : string (testdata .PackageJSON ),
81+ },
82+ expectedFiles : map [string ]string {
83+ "package.json" : string (testdata .PackageJSONAppName ),
84+ },
85+ expectedErrorType : nil ,
86+ },
87+ "pyproject.toml file exists" : {
88+ appDirName : "vibrant-butterfly-1234" ,
89+ existingFiles : map [string ]string {
90+ "pyproject.toml" : string (testdata .PyprojectTOML ),
91+ },
92+ expectedFiles : map [string ]string {
93+ "pyproject.toml" : string (testdata .PyprojectTOMLAppName ),
94+ },
95+ expectedErrorType : nil ,
96+ },
97+ "Multiple project files exist" : {
98+ appDirName : "vibrant-butterfly-1234" ,
99+ existingFiles : map [string ]string {
100+ "manifest.json" : string (testdata .ManifestJSON ),
101+ "package.json" : string (testdata .PackageJSON ),
102+ "pyproject.toml" : string (testdata .PyprojectTOML ),
103+ },
104+ expectedFiles : map [string ]string {
105+ "manifest.json" : string (testdata .ManifestJSONAppName ),
106+ "package.json" : string (testdata .PackageJSONAppName ),
107+ "pyproject.toml" : string (testdata .PyprojectTOMLAppName ),
108+ },
109+ expectedErrorType : nil ,
110+ },
77111 "No manifest files exist" : {
78112 appDirName : "vibrant-butterfly-1234" ,
79113 existingFiles : map [string ]string {},
@@ -161,3 +195,43 @@ func Test_RegexReplaceAppNameInManifest(t *testing.T) {
161195 })
162196 }
163197}
198+
199+ func Test_RegexReplaceAppNameInPackageJSON (t * testing.T ) {
200+ tests := map [string ]struct {
201+ src []byte
202+ appName string
203+ expectedSrc []byte
204+ }{
205+ "package.json name is replaced" : {
206+ src : testdata .PackageJSON ,
207+ appName : "vibrant-butterfly-1234" ,
208+ expectedSrc : testdata .PackageJSONAppName ,
209+ },
210+ }
211+ for name , tc := range tests {
212+ t .Run (name , func (t * testing.T ) {
213+ actualSrc := regexReplaceAppNameInPackageJSON (tc .src , tc .appName )
214+ require .Equal (t , tc .expectedSrc , actualSrc )
215+ })
216+ }
217+ }
218+
219+ func Test_RegexReplaceAppNameInPyprojectToml (t * testing.T ) {
220+ tests := map [string ]struct {
221+ src []byte
222+ appName string
223+ expectedSrc []byte
224+ }{
225+ "pyproject.toml name is replaced" : {
226+ src : testdata .PyprojectTOML ,
227+ appName : "vibrant-butterfly-1234" ,
228+ expectedSrc : testdata .PyprojectTOMLAppName ,
229+ },
230+ }
231+ for name , tc := range tests {
232+ t .Run (name , func (t * testing.T ) {
233+ actualSrc := regexReplaceAppNameInPyprojectToml (tc .src , tc .appName )
234+ require .Equal (t , tc .expectedSrc , actualSrc )
235+ })
236+ }
237+ }
0 commit comments