@vroskus/library-api 1.0.0 → 1.0.2

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.
package/dist/index.d.ts CHANGED
@@ -17,17 +17,18 @@ type $SetUnauthenticatedHandlerParams = {
17
17
  handler: $UnauthenticatedHandler;
18
18
  };
19
19
  type $SetUnauthenticatedHandlerResponse = void;
20
- export declare const getMock: () => AxiosMockAdapter;
21
20
  declare class ApiService<C extends $Config> {
22
21
  connection: AxiosInstance;
23
22
  unauthenticatedHandler: $UnauthenticatedHandler;
24
23
  requestContextListener: $RequestContextListener;
25
24
  responseContextListener: $ResponseContextListener;
25
+ mock: AxiosMockAdapter | null;
26
26
  constructor({ apiUrl, timeout, }: C);
27
27
  setUnauthenticatedHandler({ handler, }: $SetUnauthenticatedHandlerParams): $SetUnauthenticatedHandlerResponse;
28
28
  setRequestContextListener({ listener, }: $SetRequestContextListenerParams): $SetRequestContextListenerResponse;
29
29
  setResponseContextListener({ listener, }: $SetResponseContextListenerParams): $SetResponseContextListenerResponse;
30
30
  pushRequestContext(config: AxiosRequestConfig<unknown>, requestId: string): void;
31
31
  pushResponseContext(response: AxiosResponse<unknown>): void;
32
+ initMock(mockSetup: (mock: AxiosMockAdapter) => void): void;
32
33
  }
33
34
  export default ApiService;
package/dist/index.js CHANGED
@@ -10,6 +10,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
@@ -17,14 +29,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
30
  };
19
31
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.getMock = void 0;
21
- const axios_1 = __importDefault(require("axios"));
32
+ const axios = __importStar(require("axios"));
22
33
  const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
23
34
  const lodash_1 = __importDefault(require("lodash"));
24
35
  const uuid_1 = require("uuid");
25
36
  __exportStar(require("./types"), exports);
26
- const getMock = () => new axios_mock_adapter_1.default(axios_1.default);
27
- exports.getMock = getMock;
28
37
  class ApiService {
29
38
  constructor({ apiUrl, timeout, }) {
30
39
  const connectionConfig = {
@@ -36,7 +45,7 @@ class ApiService {
36
45
  timeout,
37
46
  withCredentials: true,
38
47
  };
39
- this.connection = axios_1.default.create(connectionConfig);
48
+ this.connection = axios.default.create(connectionConfig);
40
49
  this.unauthenticatedHandler = () => { };
41
50
  this.requestContextListener = () => { };
42
51
  this.responseContextListener = () => { };
@@ -81,6 +90,7 @@ class ApiService {
81
90
  this.pushRequestContext(config, requestId);
82
91
  return config;
83
92
  });
93
+ this.mock = null;
84
94
  }
85
95
  setUnauthenticatedHandler({ handler, }) {
86
96
  this.unauthenticatedHandler = handler;
@@ -123,5 +133,9 @@ class ApiService {
123
133
  const cleanResponseContext = lodash_1.default.omitBy(responseContext, lodash_1.default.isUndefined);
124
134
  this.responseContextListener(cleanResponseContext);
125
135
  }
136
+ initMock(mockSetup) {
137
+ this.mock = new axios_mock_adapter_1.default(this.connection);
138
+ mockSetup(this.mock);
139
+ }
126
140
  }
127
141
  exports.default = ApiService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vroskus/library-api",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Api",
5
5
  "author": "Vilius Roškus <vilius@regattas.eu>",
6
6
  "license": "MIT",
@@ -16,8 +16,10 @@
16
16
  "scripts": {
17
17
  "build": "tsc",
18
18
  "test": "npm run test:eslint && npm run test:e2e",
19
- "test:eslint": "eslint src --fix",
20
- "test:e2e": "echo 'No tests'"
19
+ "test:eslint": "eslint src test --fix",
20
+ "test:e2e": "npm run test:e2e:run && npm run test:e2e:post",
21
+ "test:e2e:run": "jest --ci --colors",
22
+ "test:e2e:post": "jest-coverage-thresholds-bumper"
21
23
  },
22
24
  "dependencies": {
23
25
  "axios": "1.6.2",
@@ -39,7 +41,30 @@
39
41
  "eslint-plugin-import-newlines": "1.3.4",
40
42
  "eslint-plugin-react": "7.33.2",
41
43
  "eslint-plugin-sort": "2.11.0",
44
+ "jest": "29.7.0",
45
+ "jest-coverage-thresholds-bumper": "1.1.0",
42
46
  "npm-check": "6.0.1",
47
+ "ts-jest": "29.1.1",
43
48
  "typescript": "5.2.2"
49
+ },
50
+ "jest": {
51
+ "preset": "ts-jest",
52
+ "testEnvironment": "node",
53
+ "coverageReporters": [
54
+ "json-summary",
55
+ "text"
56
+ ],
57
+ "collectCoverage": true,
58
+ "collectCoverageFrom": [
59
+ "src/**/*.ts"
60
+ ],
61
+ "coverageThreshold": {
62
+ "global": {
63
+ "branches": 54.54,
64
+ "functions": 50,
65
+ "lines": 70,
66
+ "statements": 67.03
67
+ }
68
+ }
44
69
  }
45
70
  }