|
7 | 7 | import org.testng.annotations.BeforeMethod;
|
8 | 8 | import org.testng.annotations.Test;
|
9 | 9 |
|
| 10 | +import java.util.*; |
| 11 | + |
10 | 12 | public class TypeScriptNodeClientCodegenTest {
|
11 | 13 |
|
12 | 14 | private TypeScriptNodeClientCodegen codegen;
|
@@ -87,9 +89,9 @@ public void modelFilenameWithMappingTest() {
|
87 | 89 | Assert.assertEquals(codegen.toModelFilename("ApiResponse"), mappedName);
|
88 | 90 | }
|
89 | 91 |
|
90 |
| - @Test(description = "prepend model import with ./ by default") |
| 92 | + @Test(description = "prepend model import with ../model by default") |
91 | 93 | public void defaultModelImportTest() {
|
92 |
| - Assert.assertEquals(codegen.toModelImport("ApiResponse"), "model/apiResponse"); |
| 94 | + Assert.assertEquals(codegen.toModelImport("ApiResponse"), "../model/apiResponse"); |
93 | 95 | }
|
94 | 96 |
|
95 | 97 | @Test(description = "use mapped name for model import when provided")
|
@@ -134,4 +136,42 @@ public void mappedApiImportTest() {
|
134 | 136 | Assert.assertEquals(codegen.toApiImport("Category"), mappedName);
|
135 | 137 | }
|
136 | 138 |
|
| 139 | + @Test(description = "correctly produces imports without import mapping") |
| 140 | + public void postProcessOperationsWithModelsTestWithoutImportMapping() { |
| 141 | + final String importName = "../model/pet"; |
| 142 | + Map<String, Object> operations = createPostProcessOperationsMapWithImportName(importName); |
| 143 | + |
| 144 | + codegen.postProcessOperationsWithModels(operations, Collections.emptyList()); |
| 145 | + List<Map<String, Object>> extractedImports = (List<Map<String, Object>>) operations.get("imports"); |
| 146 | + Assert.assertEquals(extractedImports.get(0).get("filename"), importName); |
| 147 | + } |
| 148 | + |
| 149 | + @Test(description = "correctly produces imports with import mapping") |
| 150 | + public void postProcessOperationsWithModelsTestWithImportMapping() { |
| 151 | + final String importName = "@namespace/dir/category"; |
| 152 | + Map<String, Object> operations = createPostProcessOperationsMapWithImportName(importName); |
| 153 | + |
| 154 | + codegen.postProcessOperationsWithModels(operations, Collections.emptyList()); |
| 155 | + List<Map<String, Object>> extractedImports = (List<Map<String, Object>>) operations.get("imports"); |
| 156 | + |
| 157 | + Assert.assertEquals(extractedImports.get(0).get("filename"), importName); |
| 158 | + } |
| 159 | + |
| 160 | + private Map<String, Object> createPostProcessOperationsMapWithImportName(String importName) { |
| 161 | + Map<String, Object> operations = new HashMap<String, Object>() {{ |
| 162 | + put("operation", Collections.emptyList()); |
| 163 | + put("classname", "Pet"); |
| 164 | + }}; |
| 165 | + |
| 166 | + Map<String, Object> importList = new HashMap<String, Object>() {{ |
| 167 | + put("import", importName); |
| 168 | + put("classname", "Pet"); |
| 169 | + }}; |
| 170 | + List<Map<String, Object>> imports = new ArrayList<>(); |
| 171 | + imports.add(importList); |
| 172 | + return new HashMap<String, Object>() {{ |
| 173 | + put("operations", operations); |
| 174 | + put("imports", imports); |
| 175 | + }}; |
| 176 | + } |
137 | 177 | }
|
0 commit comments