Skip to content

Commit

Permalink
add unit tests to cover #5 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored May 13, 2018
1 parent 05a2f4b commit 737e639
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

package org.openapitools.codegen.javascript;

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.*;

import org.testng.Assert;
import org.testng.annotations.Test;

import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.languages.JavascriptClientCodegen;

public class JavascriptClientCodegenTest {
Expand Down Expand Up @@ -60,4 +66,37 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
}

@Test(description = "test defaultValueWithParam for model's properties")
public void bodyParameterTest() {
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/petstore.yaml", null, new ParseOptions()).getOpenAPI();
final JavascriptClientCodegen codegen = new JavascriptClientCodegen();
final Schema pet = openAPI.getComponents().getSchemas().get("Pet");
final CodegenModel cm = codegen.fromModel("Pet", pet);

Assert.assertEquals(cm.name, "Pet");
Assert.assertEquals(cm.classname, "Pet");
Assert.assertEquals(cm.description, "A pet for sale in the pet store");
Assert.assertEquals(cm.vars.size(), 6);

// category (property)
final CodegenProperty property1 = cm.vars.get(1);
Assert.assertEquals(property1.baseName, "category");
Assert.assertEquals(property1.datatype, "Category");
Assert.assertEquals(property1.name, "category");
Assert.assertEquals(property1.baseType, "Category");
Assert.assertEquals(property1.defaultValueWithParam, " = Category.constructFromObject(data['category']);");
Assert.assertFalse(property1.required);
Assert.assertFalse(property1.isContainer);

// name (property)
final CodegenProperty property2 = cm.vars.get(2);
Assert.assertEquals(property2.baseName, "name");
Assert.assertEquals(property2.datatype, "String");
Assert.assertEquals(property2.name, "name");
Assert.assertEquals(property2.baseType, "String");
Assert.assertEquals(property2.defaultValueWithParam, " = ApiClient.convertToType(data['name'], 'String');");
Assert.assertTrue(property2.required); // test required
Assert.assertFalse(property2.isContainer);
}

}

0 comments on commit 737e639

Please sign in to comment.