@evanion/nestjs-correlation-id 1.0.4 → 2.0.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.
- package/CHANGELOG.md +59 -1
- package/README.md +100 -34
- package/dist/constants.d.ts +16 -1
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -5
- package/dist/correlation-id.middleware.d.ts +5 -4
- package/dist/correlation-id.middleware.d.ts.map +1 -0
- package/dist/correlation-id.middleware.js +35 -30
- package/dist/correlation.module.d.ts +2 -1
- package/dist/correlation.module.d.ts.map +1 -0
- package/dist/correlation.module.js +16 -19
- package/dist/correlation.service.d.ts +34 -3
- package/dist/correlation.service.d.ts.map +1 -0
- package/dist/correlation.service.js +49 -26
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -21
- package/dist/interfaces/correlation-config.interface.d.ts +2 -0
- package/dist/interfaces/correlation-config.interface.d.ts.map +1 -0
- package/dist/interfaces/correlation-config.interface.js +1 -2
- package/dist/withCorrelation.function.d.ts +16 -74
- package/dist/withCorrelation.function.d.ts.map +1 -0
- package/dist/withCorrelation.function.js +41 -22
- package/package.json +76 -62
- package/src/constants.ts +19 -0
- package/src/correlation-id.middleware.ts +55 -0
- package/src/correlation.module.ts +32 -0
- package/src/correlation.service.ts +69 -0
- package/src/index.ts +6 -0
- package/src/interfaces/correlation-config.interface.ts +5 -0
- package/src/withCorrelation.function.ts +60 -0
- package/CONTRIBUTING.md +0 -31
- package/dist/correlation-id.middleware.spec.d.ts +0 -1
- package/dist/correlation-id.middleware.spec.js +0 -62
- package/dist/correlation.service.spec.d.ts +0 -1
- package/dist/correlation.service.spec.js +0 -35
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const correlation_id_middleware_1 = require("./correlation-id.middleware");
|
|
4
|
-
const mockCorrelationConfig = {
|
|
5
|
-
header: 'x-correlation-id',
|
|
6
|
-
generator: () => '12345',
|
|
7
|
-
};
|
|
8
|
-
const mockCorrelationService = {
|
|
9
|
-
getCorrelationId: jest.fn().mockImplementation(() => 'test123'),
|
|
10
|
-
setCorrelationId: jest.fn(),
|
|
11
|
-
};
|
|
12
|
-
describe('CorrelationIdMiddleware', () => {
|
|
13
|
-
let middleware;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
middleware = new correlation_id_middleware_1.CorrelationIdMiddleware(mockCorrelationService, mockCorrelationConfig);
|
|
16
|
-
});
|
|
17
|
-
it('should be defined', () => {
|
|
18
|
-
expect(middleware).toBeDefined();
|
|
19
|
-
});
|
|
20
|
-
it('should set the correlation id in request object', () => {
|
|
21
|
-
const req = {
|
|
22
|
-
get: jest.fn(),
|
|
23
|
-
headers: {},
|
|
24
|
-
};
|
|
25
|
-
const res = {
|
|
26
|
-
get: jest.fn(),
|
|
27
|
-
set: jest.fn(),
|
|
28
|
-
headers: {},
|
|
29
|
-
};
|
|
30
|
-
jest.spyOn(res, 'set');
|
|
31
|
-
middleware.use(req, res, jest.fn());
|
|
32
|
-
expect(req.headers['x-correlation-id']).toBe('test123');
|
|
33
|
-
});
|
|
34
|
-
it('should set the correlation id in response object', () => {
|
|
35
|
-
const req = {
|
|
36
|
-
get: jest.fn().mockImplementation(() => 'test123'),
|
|
37
|
-
headers: {},
|
|
38
|
-
};
|
|
39
|
-
const res = {
|
|
40
|
-
get: jest.fn(),
|
|
41
|
-
set: jest.fn(),
|
|
42
|
-
headers: {},
|
|
43
|
-
};
|
|
44
|
-
jest.spyOn(res, 'set');
|
|
45
|
-
middleware.use(req, res, () => { });
|
|
46
|
-
expect(res.set).toHaveBeenCalledWith('x-correlation-id', 'test123');
|
|
47
|
-
});
|
|
48
|
-
it('should set the correlation id in correlationService', () => {
|
|
49
|
-
const req = {
|
|
50
|
-
get: jest.fn().mockImplementation(() => 'test123'),
|
|
51
|
-
headers: {},
|
|
52
|
-
};
|
|
53
|
-
const res = {
|
|
54
|
-
get: jest.fn(),
|
|
55
|
-
set: jest.fn(),
|
|
56
|
-
headers: {},
|
|
57
|
-
};
|
|
58
|
-
jest.spyOn(res, 'set');
|
|
59
|
-
middleware.use(req, res, jest.fn());
|
|
60
|
-
expect(mockCorrelationService.setCorrelationId).toHaveBeenCalledWith('test123');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const testing_1 = require("@nestjs/testing");
|
|
13
|
-
const constants_1 = require("./constants");
|
|
14
|
-
const correlation_service_1 = require("./correlation.service");
|
|
15
|
-
describe('CorrelationService', () => {
|
|
16
|
-
let service;
|
|
17
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const module = yield testing_1.Test.createTestingModule({
|
|
19
|
-
providers: [
|
|
20
|
-
correlation_service_1.CorrelationService,
|
|
21
|
-
{
|
|
22
|
-
provide: constants_1.CORRELATION_CONFIG_TOKEN,
|
|
23
|
-
useValue: {
|
|
24
|
-
header: constants_1.CORRELATION_ID_HEADER,
|
|
25
|
-
generator: () => 'test-id',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
}).compile();
|
|
30
|
-
service = yield module.resolve(correlation_service_1.CorrelationService);
|
|
31
|
-
}));
|
|
32
|
-
it('should be defined', () => {
|
|
33
|
-
expect(service).toBeDefined();
|
|
34
|
-
});
|
|
35
|
-
});
|