diff --git a/CHANGELOG.md b/CHANGELOG.md index da3486c..de6bb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +* Option to generate properties with snake_case(#295) + ## 0.4.2 * Use statement not available on Azure SQL (#243) diff --git a/test/modelCustomization/modelCustomization.test.ts b/test/modelCustomization/modelCustomization.test.ts index 8443f1f..e42aaa0 100644 --- a/test/modelCustomization/modelCustomization.test.ts +++ b/test/modelCustomization/modelCustomization.test.ts @@ -30,6 +30,12 @@ describe("Model customization phase", async () => { options: { name: "name" }, tscName: "name", tscType: "string" + }, + { + type: "character varying", + options: { name: "complicatedName" }, + tscName: "complexName", + tscType: "string" } ], indices: [ @@ -251,6 +257,7 @@ describe("Model customization phase", async () => { .toString(); expect(postContent).to.contain("Title: string;"); expect(postAuthorContent).to.contain("Posts: Post[];"); + expect(postAuthorContent).to.contain("ComplexName: string;"); compileGeneratedModel(generationOptions.resultsPath, [""], false); }); @@ -279,9 +286,39 @@ describe("Model customization phase", async () => { .toString(); expect(postContent).to.contain("title: string;"); expect(postAuthorContent).to.contain("posts: Post[];"); + expect(postAuthorContent).to.contain("complexName: string;"); compileGeneratedModel(generationOptions.resultsPath, [""]); }); + it("snake_case", () => { + const data = generateSampleData(); + const generationOptions = generateGenerationOptions(); + clearGenerationDir(); + + generationOptions.convertCaseProperty = "snake"; + const customizedModel = modelCustomizationPhase( + data, + generationOptions, + {} + ); + modelGenerationPhase( + getDefaultConnectionOptions(), + generationOptions, + customizedModel + ); + const filesGenPath = path.resolve(resultsPath, "entities"); + const postContent = fs + .readFileSync(path.resolve(filesGenPath, "Post.ts")) + .toString(); + const postAuthorContent = fs + .readFileSync(path.resolve(filesGenPath, "PostAuthor.ts")) + .toString(); + expect(postContent).to.contain("title: string;"); + expect(postAuthorContent).to.contain("posts: Post[];"); + expect(postAuthorContent).to.contain("complex_name: string;"); + + compileGeneratedModel(generationOptions.resultsPath, [""],false); + }); }); describe("EOL", async () => { it("LF", () => {