@terreno/api 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import express from "express";
5
5
  import supertest from "supertest";
6
6
  import winston from "winston";
7
7
 
8
+ import type {UserModel as UserModelType} from "./auth";
8
9
  import {
9
10
  createRouter,
10
11
  createRouterWithAuth,
@@ -17,6 +18,8 @@ import {logger, winstonLogger} from "./logger";
17
18
  import {TerrenoApp} from "./terrenoApp";
18
19
  import {UserModel} from "./tests";
19
20
 
21
+ const typedUserModel = UserModel as unknown as UserModelType;
22
+
20
23
  describe("expressServer", () => {
21
24
  describe("setupEnvironment", () => {
22
25
  const originalEnv = process.env;
@@ -821,7 +824,7 @@ describe("expressServer", () => {
821
824
  const app = new TerrenoApp({
822
825
  configureApp,
823
826
  skipListen: false,
824
- userModel: UserModel as any,
827
+ userModel: typedUserModel,
825
828
  }).start();
826
829
  expect(app).toBeDefined();
827
830
  } finally {
@@ -829,21 +832,27 @@ describe("expressServer", () => {
829
832
  }
830
833
  });
831
834
 
832
- it("handles listen error with invalid port", () => {
833
- process.env.PORT = "-1";
835
+ it("handles listen errors", () => {
834
836
  const configureApp = (): void => {};
837
+ const http = require("node:http") as typeof import("node:http");
838
+ const originalListen = http.Server.prototype.listen;
835
839
  const originalExit = process.exit;
836
- process.exit = (() => {}) as unknown as typeof process.exit;
840
+ const exit = mock(() => undefined);
841
+ process.exit = exit as unknown as typeof process.exit;
842
+ http.Server.prototype.listen = mock(() => {
843
+ throw new Error("listen failed");
844
+ }) as unknown as typeof originalListen;
837
845
  try {
838
846
  new TerrenoApp({
839
847
  configureApp,
840
848
  skipListen: false,
841
- userModel: UserModel as any,
849
+ userModel: typedUserModel,
842
850
  }).start();
843
- } catch {
844
- // May throw
851
+ expect(exit).toHaveBeenCalledWith(1);
852
+ } finally {
853
+ http.Server.prototype.listen = originalListen;
854
+ process.exit = originalExit;
845
855
  }
846
- process.exit = originalExit;
847
856
  });
848
857
  });
849
858