Skip to content

Commit a2d7c4e

Browse files
fix tests
1 parent b1e7348 commit a2d7c4e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/openapi-typescript-server/src/cli/generate.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe("tags", () => {
254254
const tagType = sourceFile.getTypeAlias("Tag");
255255
assert(tagType);
256256
assert(tagType.isExported());
257-
const tagTypeText = tagType.getType().getText();
257+
const tagTypeText = tagType.getTypeNode()?.getText() || "";
258258
assert.match(tagTypeText, /"pet"/);
259259
assert.match(tagTypeText, /"user"/);
260260
});
@@ -284,7 +284,7 @@ describe("tags", () => {
284284
const tagType = sourceFile.getTypeAlias("Tag");
285285
assert(tagType);
286286
assert(tagType.isExported());
287-
const tagTypeText = tagType.getType().getText();
287+
const tagTypeText = tagType.getTypeNode()?.getText() || "";
288288
assert.equal(tagTypeText, "null");
289289
});
290290

@@ -327,7 +327,7 @@ describe("tags", () => {
327327
const sourceFile = generate(spec, "./schema.d.ts", "outdir.ts");
328328
const tagType = sourceFile.getTypeAlias("Tag");
329329
assert(tagType);
330-
const tagTypeText = tagType.getType().getText();
330+
const tagTypeText = tagType.getTypeNode()?.getText() || "";
331331
assert.match(tagTypeText, /"pet"/);
332332
assert.match(tagTypeText, /null/);
333333
});
@@ -371,9 +371,11 @@ describe("registerRouteHandlersByTag", () => {
371371
const serverParam = func.getParameters()[1];
372372
assert(serverParam);
373373
assert.equal(serverParam.getName(), "server");
374-
assert.match(serverParam.getType().getText(), /Partial<Server<Req, Res>>/);
374+
const serverTypeText = serverParam.getTypeNode()?.getText() || "";
375+
assert.match(serverTypeText, /Partial<Server<Req, Res>>/);
375376

376-
assert.match(func.getReturnType().getText(), /Route\[\]/);
377+
const returnTypeText = func.getReturnTypeNode()?.getText() || "";
378+
assert.match(returnTypeText, /Route\[\]/);
377379
});
378380

379381
it("generates switch statement for each tag", () => {
@@ -420,8 +422,8 @@ describe("registerRouteHandlersByTag", () => {
420422
assert.match(bodyText, /switch \(tag\)/);
421423
assert.match(bodyText, /case "pet":/);
422424
assert.match(bodyText, /case "user":/);
423-
assert.match(bodyText, /if \(server\.listPets\)/);
424-
assert.match(bodyText, /if \(server\.listUsers\)/);
425+
assert.match(bodyText, /handler: server\.listPets/);
426+
assert.match(bodyText, /handler: server\.listUsers/);
425427
});
426428

427429
it("groups operations by tag correctly", () => {
@@ -467,8 +469,8 @@ describe("registerRouteHandlersByTag", () => {
467469
const petCaseMatch = bodyText.match(/case "pet":[\s\S]*?break;/);
468470
assert(petCaseMatch);
469471
const petCaseBlock = petCaseMatch[0];
470-
assert.match(petCaseBlock, /if \(server\.listPets\)/);
471-
assert.match(petCaseBlock, /if \(server\.createPet\)/);
472+
assert.match(petCaseBlock, /handler: server\.listPets/);
473+
assert.match(petCaseBlock, /handler: server\.createPet/);
472474
});
473475

474476
it("handles untagged operations with null case", () => {
@@ -497,7 +499,7 @@ describe("registerRouteHandlersByTag", () => {
497499
const bodyText = func?.getBodyText() || "";
498500

499501
assert.match(bodyText, /case null:/);
500-
assert.match(bodyText, /if \(server\.getStatus\)/);
502+
assert.match(bodyText, /handler: server\.getStatus/);
501503
});
502504
});
503505

0 commit comments

Comments
 (0)